diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2017-05-29 14:18:59 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2017-05-29 14:18:59 +0200 |
| commit | 903069a6f4efec666a4dbfb3b2d375caf9e32dbe (patch) | |
| tree | da46d689d23b631f45a5be999e0b157aaccc868f | |
| parent | 2f0de0e85ff02ef72ff2f09076077566bf4e8ba2 (diff) | |
| download | PROJ-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.c | 12 |
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; } |
