[njs] Fixed initialization of external prototypes with object entry.

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


details:   https://hg.nginx.org/njs/rev/ee4d396aa418
branches:  
changeset: 2255:ee4d396aa418
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Jan 08 16:40:42 2024 -0800
description:
Fixed initialization of external prototypes with object entry.

When external was NULL (for example, when .u.object.properties is not
declared), an arithmetic operation was performed with NULL pointer which
is undefined behavior.

Found by UndefinedBehaviorSanitizer.

diffstat:

 src/njs_extern.c |  4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diffs (14 lines):

diff -r c43745da92cd -r ee4d396aa418 src/njs_extern.c
--- a/src/njs_extern.c	Mon Jan 08 16:40:42 2024 -0800
+++ b/src/njs_extern.c	Mon Jan 08 16:40:42 2024 -0800
@@ -34,6 +34,10 @@ njs_external_add(njs_vm_t *vm, njs_arr_t
     hash = &slot->external_shared_hash;
     njs_lvlhsh_init(hash);
 
+    if (n == 0) {
+        return NJS_OK;
+    }
+
     lhq.replace = 0;
     lhq.proto = &njs_object_hash_proto;
     lhq.pool = vm->mem_pool;


More information about the nginx-devel mailing list