From 2de3bfb9f671a9ac243b47897ccef2434dacc3e0 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 26 May 2020 19:02:57 +0000 Subject: [PATCH] Fixed potential undefined behavior in memcpy(). The issue was introduced in 1d0825906438. Found with Clang Static Analyzer. --- src/njs_array.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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; -- 2.47.3