summaryrefslogtreecommitdiffhomepage
path: root/src/http
diff options
context:
space:
mode:
authorDavid Korczynski <david@adalogics.com>2026-03-04 01:27:45 -0800
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>2026-04-06 14:07:18 +0400
commit06c30ec29d392af00157c0b0eecbc545b330e50f (patch)
tree4a572969d8388447403e303e9a265183867b8879 /src/http
parent2ff1a969f3040f27ac2610e9840a4e802bcc39cc (diff)
downloadnginx-06c30ec29d392af00157c0b0eecbc545b330e50f.tar.gz
nginx-06c30ec29d392af00157c0b0eecbc545b330e50f.tar.bz2
Upstream: fix integer underflow in charset parsing
The issue described below was only reproducible prior to https://github.com/nginx/nginx/commit/7924a4ec6cb35291ea60a5f2a70ac0a034d94ff7 When parsing the `charset` parameter in the `Content-Type` header within `ngx_http_upstream_copy_content_type`, an input such as `charset="` resulted in an integer underflow. In this scenario, both `p` and `last` point to the position immediately following the opening quote. The logic to strip a trailing quote checked `*(last - 1)` without verifying that `last > p`. This caused `last` to be decremented to point to the opening quote itself, making `last < p`. The subsequent length calculation `r->headers_out.charset.len = last - p` resulted in -1, which wrapped to `SIZE_MAX` as `len` is a `size_t`. This invalid length was later passed to `ngx_cpymem` in `ngx_http_header_filter`, leading to an out-of-bounds memory access (detected as `negative-size-param` by AddressSanitizer). The fix ensures `last > p` before attempting to strip a trailing quote, correctly resulting in a zero-length charset for malformed input. The oss-fuzz payload that triggers this issue holds multiple 103 status lines, and it's a sequence of 2 of those Content-Type headers that trigger the ASAN report. Co-authored-by: CodeMender <codemender-patching@google.com> Fixes: https://issues.oss-fuzz.com/issues/486561029 Signed-off-by: David Korczynski <david@adalogics.com>
Diffstat (limited to 'src/http')
-rw-r--r--src/http/ngx_http_upstream.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index c84defaa9..918323d9b 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -5652,7 +5652,7 @@ ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h,
last = h->value.data + h->value.len;
- if (*(last - 1) == '"') {
+ if (last > p && *(last - 1) == '"') {
last--;
}