]> git.kaiwu.me - njs.git/commitdiff
Fixed initialization of external prototypes with object entry.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 9 Jan 2024 00:40:42 +0000 (16:40 -0800)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 9 Jan 2024 00:40:42 +0000 (16:40 -0800)
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.

src/njs_extern.c

index 50ac76c4189f7ec3388323ac7927490e3e67b80d..329ed69d59e34945ba4820e7aaa26334143b43f1 100644 (file)
@@ -34,6 +34,10 @@ njs_external_add(njs_vm_t *vm, njs_arr_t *protos,
     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;