From 903069a6f4efec666a4dbfb3b2d375caf9e32dbe Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Mon, 29 May 2017 14:18:59 +0200 Subject: Fix undefined behaviour on memcpy() when provided with NULL source. Found when running 'make check' on a build with -fsanitize=undefined,address --- src/pj_initcache.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pj_initcache.c b/src/pj_initcache.c index e36b0abc..30ac2aab 100644 --- a/src/pj_initcache.c +++ b/src/pj_initcache.c @@ -150,14 +150,20 @@ void pj_insert_initcache( const char *filekey, const paralist *list ) cache_alloc = cache_alloc * 2 + 15; cache_key_new = (char **) pj_malloc(sizeof(char*) * cache_alloc); - memcpy( cache_key_new, cache_key, sizeof(char*) * cache_count); + if( cache_key && cache_count ) + { + memcpy( cache_key_new, cache_key, sizeof(char*) * cache_count); + } pj_dalloc( cache_key ); cache_key = cache_key_new; cache_paralist_new = (paralist **) pj_malloc(sizeof(paralist*) * cache_alloc); - memcpy( cache_paralist_new, cache_paralist, - sizeof(paralist*) * cache_count ); + if( cache_paralist && cache_count ) + { + memcpy( cache_paralist_new, cache_paralist, + sizeof(paralist*) * cache_count ); + } pj_dalloc( cache_paralist ); cache_paralist = cache_paralist_new; } -- cgit v1.2.3