From de7e1aadc7d0795bc8f9a1c9898379e9455ea41e Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Mon, 8 Jan 2024 16:40:42 -0800 Subject: [PATCH] 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. --- src/njs_extern.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/njs_extern.c b/src/njs_extern.c index 50ac76c4..329ed69d 100644 --- a/src/njs_extern.c +++ b/src/njs_extern.c @@ -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; -- 2.47.3