aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2017-05-29 14:18:59 +0200
committerEven Rouault <even.rouault@spatialys.com>2017-05-29 14:18:59 +0200
commit903069a6f4efec666a4dbfb3b2d375caf9e32dbe (patch)
treeda46d689d23b631f45a5be999e0b157aaccc868f
parent2f0de0e85ff02ef72ff2f09076077566bf4e8ba2 (diff)
downloadPROJ-903069a6f4efec666a4dbfb3b2d375caf9e32dbe.tar.gz
PROJ-903069a6f4efec666a4dbfb3b2d375caf9e32dbe.zip
Fix undefined behaviour on memcpy() when provided with NULL source. Found when running 'make check' on a build with -fsanitize=undefined,address
-rw-r--r--src/pj_initcache.c12
1 files changed, 9 insertions, 3 deletions
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;
}