]> git.kaiwu.me - njs.git/commit
HTTP: fix segfault reading a request header with no cache slot
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 12 Jun 2026 03:57:14 +0000 (20:57 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 12 Jun 2026 14:48:29 +0000 (07:48 -0700)
commit241dffa95d8ec2b237b1cf19eb105e0a824874fc
tree4e71f5b914d737e6df21ea3261bec22e51e93d96
parent02d83583dd698eb1e989f271d9854d78c5de87de
HTTP: fix segfault reading a request header with no cache slot

Reading a request header via r.headersIn[name] could crash the worker
with SIGSEGV.  The header in question was "Proxy-Connection", but any
header that nginx registers without a dedicated ngx_table_elt_t * slot
was affected.

The getter mapped an arbitrary header name through ngx_hash_find() and
treated (char *) &r->headers_in + hh->offset as a pointer to a cache
slot.  This only holds for headers whose parser stores into such a
slot.  "Proxy-Connection" is registered in ngx_http_headers_in[] with
offset 0 and a handler that stores nothing, so the getter aliased the
ngx_list_t at the start of ngx_http_headers_in_t and followed its elts
pointer as a bogus ngx_table_elt_t.

The fix is to walk the parsed header list by name, as it is always safe.
The single-value and semicolon-join flags moved into the per-name header
table, and the now-unused slot pointer argument and its branch were
dropped from the generic getter.

The slot lookup that is removed was only an optimization for the names
in ngx_http_headers_in[]; for any other header it missed the hash and
walked the list anyway, so dropping it is not a performance regression.

This closes #1071 issue on Github.
nginx/ngx_http_js_module.c
nginx/t/js_headers.t