[njs] Fixed potential undefined behavior in memcpy().

Dmitry Volyntsev xeioex at nginx.com
Wed May 27 13:39:47 UTC 2020


details:   https://hg.nginx.org/njs/rev/164801c99e9a
branches:  
changeset: 1402:164801c99e9a
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue May 26 19:02:57 2020 +0000
description:
Fixed potential undefined behavior in memcpy().

The issue was introduced in 1d0825906438.

Found with Clang Static Analyzer.

diffstat:

 src/njs_array.c |  8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diffs (20 lines):

diff -r db77713e0536 -r 164801c99e9a src/njs_array.c
--- a/src/njs_array.c	Tue May 26 16:35:11 2020 +0000
+++ b/src/njs_array.c	Tue May 26 19:02:57 2020 +0000
@@ -3318,11 +3318,13 @@ njs_array_prototype_sort(njs_vm_t *vm, n
                     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;


More information about the nginx-devel mailing list