[njs] Improved array enumeration with length 0.

Dmitry Volyntsev xeioex at nginx.com
Tue Jan 9 00:57:21 UTC 2024


details:   https://hg.nginx.org/njs/rev/41d0de3ad198
branches:  
changeset: 2256:41d0de3ad198
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Jan 08 16:40:42 2024 -0800
description:
Improved array enumeration with length 0.

The fix eliminates an arithmetic operation with NULL pointer.

Found by UndefinedBehaviorSanitizer.

diffstat:

 src/njs_object.c |  2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diffs (12 lines):

diff -r ee4d396aa418 -r 41d0de3ad198 src/njs_object.c
--- a/src/njs_object.c	Mon Jan 08 16:40:42 2024 -0800
+++ b/src/njs_object.c	Mon Jan 08 16:40:42 2024 -0800
@@ -591,7 +591,7 @@ njs_object_enumerate_array(njs_vm_t *vm,
     njs_value_t  *p, *start, *end;
     njs_array_t  *entry;
 
-    if (!array->object.fast_array) {
+    if (!array->object.fast_array || array->length == 0) {
         return NJS_OK;
     }
 


More information about the nginx-devel mailing list