]> git.kaiwu.me - njs.git/commitdiff
QuickJS: fixed fetch error-handling typos
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 22 May 2026 04:05:59 +0000 (21:05 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 26 May 2026 21:45:24 +0000 (14:45 -0700)
Returned the JS_ThrowOutOfMemory() result from
ngx_qjs_fetch_response_ctor() on ngx_list_init() failure: previously
the call result was discarded and execution fell through.

Replaced a stale "ret" check with "rc" after ngx_qjs_headers_fill(),
so a non-NGX_OK return is no longer ignored.

Added a NULL check after JS_ToCStringLen() on the header key in
ngx_qjs_headers_ext_keys(), and replaced a stale "value" check with
"item" when testing JS_NewStringLen() for failure.

nginx/ngx_qjs_fetch.c

index 7c0a7a34d09a3329b0910c9c1df508dd6d3c7378..066088ce6e5694e20f2cb2922c630166c7dec2f2 100644 (file)
@@ -759,7 +759,7 @@ ngx_qjs_fetch_response_ctor(JSContext *cx, JSValueConst new_target, int argc,
     ret = ngx_list_init(&response->headers.header_list, pool, 4,
                         sizeof(ngx_js_tb_elt_t));
     if (ret != NGX_OK) {
-        JS_ThrowOutOfMemory(cx);
+        return JS_ThrowOutOfMemory(cx);
     }
 
     init = argv[1];
@@ -825,7 +825,7 @@ ngx_qjs_fetch_response_ctor(JSContext *cx, JSValueConst new_target, int argc,
             rc = ngx_qjs_headers_fill(cx, &response->headers, value);
             JS_FreeValue(cx, value);
 
-            if (ret != NGX_OK) {
+            if (rc != NGX_OK) {
                 return JS_EXCEPTION;
             }
         }
@@ -1458,6 +1458,9 @@ ngx_qjs_headers_ext_keys(JSContext *cx, JSValue value)
 
             hdr.data = (u_char *) JS_ToCStringLen(cx, &hdr.len, key);
             JS_FreeValue(cx, key);
+            if (hdr.data == NULL) {
+                goto fail;
+            }
 
             found = h[i].key.len == hdr.len
                     && ngx_strncasecmp(h[i].key.data,
@@ -1473,7 +1476,7 @@ ngx_qjs_headers_ext_keys(JSContext *cx, JSValue value)
         if (k == n) {
             item = JS_NewStringLen(cx, (const char *) h[i].key.data,
                                     h[i].key.len);
-            if (JS_IsException(value)) {
+            if (JS_IsException(item)) {
                 goto fail;
             }