Skip to content

Commit e21d9b5

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 3010cad commit e21d9b5

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/ngx_http_lua_headers_in.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ ngx_http_set_header_helper(ngx_http_request_t *r, ngx_http_lua_header_val_t *hv,
263263

264264
new_header:
265265

266+
if (r->headers_in.headers.last == NULL) {
267+
/* must be 400 bad request */
268+
return NGX_OK;
269+
}
270+
266271
h = ngx_list_push(&r->headers_in.headers);
267272

268273
if (h == NULL) {

t/028-req-header.t

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Test::Nginx::Socket::Lua;
88

99
repeat_each(2);
1010

11-
plan tests => repeat_each() * (2 * blocks() + 28);
11+
plan tests => repeat_each() * (2 * blocks() + 30);
1212

1313
#no_diff();
1414
#no_long_string();
@@ -1582,3 +1582,41 @@ X-Forwarded-For: 8.8.8.8
15821582
Foo: 127.0.0.1
15831583
--- no_error_log
15841584
[error]
1585+
1586+
1587+
1588+
=== TEST 52: for bad requests (bad request method letter case)
1589+
--- config
1590+
error_page 400 = /err;
1591+
1592+
location = /err {
1593+
content_by_lua_block {
1594+
ngx.req.set_header("Foo", "bar")
1595+
ngx.say("ok")
1596+
}
1597+
}
1598+
--- raw_request
1599+
GeT / HTTP/1.1
1600+
--- response_body
1601+
ok
1602+
--- no_error_log
1603+
[error]
1604+
1605+
1606+
1607+
=== TEST 53: for bad requests (bad request method names)
1608+
--- config
1609+
error_page 400 = /err;
1610+
1611+
location = /err {
1612+
content_by_lua_block {
1613+
ngx.req.set_header("Foo", "bar")
1614+
ngx.say("ok")
1615+
}
1616+
}
1617+
--- raw_request
1618+
GET x HTTP/1.1
1619+
--- response_body
1620+
ok
1621+
--- no_error_log
1622+
[error]

0 commit comments

Comments
 (0)