]> git.kaiwu.me - njs.git/commitdiff
HTTP: fixed missing exceptions in njs handlers
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 3 Jun 2026 02:05:53 +0000 (19:05 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 3 Jun 2026 21:34:17 +0000 (14:34 -0700)
Set pending exceptions before returning NJS_ERROR from njs response output
paths.  Previously sendHeader(), send(), and finish() could fail without an
exception being available to the VM.

nginx/ngx_http_js_module.c

index 447ead13432eb11568cd517629b63f83e70f6365..78de01c597a98497bf6dbbbb414d38a7d4502fba 100644 (file)
@@ -2983,12 +2983,14 @@ ngx_http_js_ext_send_header(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     }
 
     if (ngx_http_set_content_type(r) != NGX_OK) {
+        njs_vm_internal_error(vm, "failed to set content type");
         return NJS_ERROR;
     }
 
     r->disable_not_modified = 1;
 
     if (ngx_http_send_header(r) == NGX_ERROR) {
+        njs_vm_internal_error(vm, "failed to send header");
         return NJS_ERROR;
     }
 
@@ -3037,6 +3039,7 @@ ngx_http_js_ext_send(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
         b = ngx_calloc_buf(r->pool);
         if (b == NULL) {
+            njs_vm_memory_error(vm);
             return NJS_ERROR;
         }
 
@@ -3048,6 +3051,7 @@ ngx_http_js_ext_send(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
 
         cl = ngx_alloc_chain_link(r->pool);
         if (cl == NULL) {
+            njs_vm_memory_error(vm);
             return NJS_ERROR;
         }
 
@@ -3060,6 +3064,7 @@ ngx_http_js_ext_send(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     *ll = NULL;
 
     if (ngx_http_output_filter(r, out) == NGX_ERROR) {
+        njs_vm_internal_error(vm, "failed to send response");
         return NJS_ERROR;
     }
 
@@ -3217,6 +3222,7 @@ ngx_http_js_ext_finish(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
     }
 
     if (ngx_http_send_special(r, NGX_HTTP_LAST) == NGX_ERROR) {
+        njs_vm_internal_error(vm, "failed to send response");
         return NJS_ERROR;
     }