Skip to content

Commit 0a5bad9

Browse files
committed
bugfix: when the nginx core does not properly initialize r->headers_in.headers (due to 400 bad requests and etc), more_set_input_headers might lead to crashes. thanks Marcin Teodorczyk for the report.
1 parent 7fc3397 commit 0a5bad9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/ngx_http_headers_more_headers_in.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ ngx_http_set_header_helper(ngx_http_request_t *r,
290290
return NGX_OK;
291291
}
292292

293+
if (r->headers_in.headers.last == NULL) {
294+
/* must be 400 bad request */
295+
return NGX_OK;
296+
}
297+
293298
h = ngx_list_push(&r->headers_in.headers);
294299

295300
if (h == NULL) {

t/bug.t

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Test::Nginx::Socket; # 'no_plan';
44

55
repeat_each(2);
66

7-
plan tests => 49 * repeat_each();
7+
plan tests => 53 * repeat_each();
88

99
no_diff;
1010

@@ -360,3 +360,32 @@ X-Foo: Bar
360360
--- response_body
361361
ok
362362
363+
364+
365+
=== TEST 19: for bad requests (bad request method letter case)
366+
--- config
367+
error_page 400 = /err;
368+
369+
location = /err {
370+
more_set_input_headers "Foo: bar";
371+
echo ok;
372+
}
373+
--- raw_request
374+
GeT / HTTP/1.1
375+
--- response_body
376+
ok
377+
378+
379+
380+
=== TEST 20: for bad requests (bad request method names)
381+
--- config
382+
error_page 400 = /err;
383+
384+
location = /err {
385+
more_set_input_headers "Foo: bar";
386+
echo ok;
387+
}
388+
--- raw_request
389+
GET x HTTP/1.1
390+
--- response_body
391+
ok

0 commit comments

Comments
 (0)