From: Dmitry Volyntsev Date: Tue, 9 Jan 2024 00:40:42 +0000 (-0800) Subject: Fixed initialization of external prototypes with object entry. X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=de7e1aadc7d0795bc8f9a1c9898379e9455ea41e;p=njs.git 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. --- 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;