]> git.kaiwu.me - njs.git/commitdiff
Fixed missed allocation check in promise code.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 25 Nov 2025 23:58:38 +0000 (15:58 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Mon, 1 Dec 2025 17:12:47 +0000 (09:12 -0800)
Found by Coverity (CID 16469311646932).

src/njs_promise.c

index 86ea334dd632a5f276c926d57fd67cd4b4e99a68..53a8c4e25838f938d63f8d1087a2d7755642bc3c 100644 (file)
@@ -876,6 +876,10 @@ njs_promise_perform_then(njs_vm_t *vm, njs_value_t *value,
     } else {
         function = njs_promise_create_function(vm,
                                                sizeof(njs_promise_context_t));
+        if (njs_slow_path(function == NULL)) {
+            return NJS_ERROR;
+        }
+
         function->u.native = njs_promise_reaction_job;
 
         if (data->state == NJS_PROMISE_REJECTED) {
@@ -967,6 +971,10 @@ njs_promise_prototype_finally(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     finally = njs_arg(args, nargs, 1);
 
     function = njs_promise_create_function(vm, sizeof(njs_promise_context_t));
+    if (njs_slow_path(function == NULL)) {
+        return NJS_ERROR;
+    }
+
     function->u.native = njs_promise_constructor;
 
     njs_set_function(&constructor, function);