From: Dmitry Volyntsev Date: Tue, 26 May 2020 19:02:57 +0000 (+0000) Subject: Fixed potential undefined behavior in memcpy(). X-Git-Tag: 0.4.2~56 X-Git-Url: http://git.kaiwu.me/postgresql/log/contrib/postgres_fdw/static/gitweb.js?a=commitdiff_plain;h=2de3bfb9f671a9ac243b47897ccef2434dacc3e0;p=njs.git Fixed potential undefined behavior in memcpy(). The issue was introduced in 1d0825906438. Found with Clang Static Analyzer. --- diff --git a/src/njs_array.c b/src/njs_array.c index baad4d36..c1acc6b9 100644 --- a/src/njs_array.c +++ b/src/njs_array.c @@ -3318,11 +3318,13 @@ njs_array_prototype_sort(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, return NJS_ERROR; } - p = (void *) njs_cpymem(nslots, slots, - sizeof(njs_array_sort_slot_t) * (p - slots)); - if (slots != NULL) { + p = (void *) njs_cpymem(nslots, slots, + sizeof(njs_array_sort_slot_t) * (p - slots)); njs_mp_free(vm->mem_pool, slots); + + } else { + p = nslots; } slots = nslots;