Skip to content

bugfix: first part headers will be discard when using single LF as delimiter #1204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/ngx_http_lua_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)

if (b != mr->header_in) {
/* skip truncated header entries (if any) */
while (last > data && last[-1] != LF) {
while (last > data && last[-1] != LF && last[-1] != '\0') {
last--;
}
}
Expand Down Expand Up @@ -315,7 +315,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)

#if 1
/* skip truncated header entries (if any) */
while (last > p && last[-1] != LF) {
while (last > p && last[-1] != LF && last[-1] != '\0') {
last--;
}
#endif
Expand All @@ -325,8 +325,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
if (*p == '\0') {
j++;
if (p + 1 == last) {
/* XXX this should not happen */
dd("found string end!!");
*p = LF;

} else if (*(p + 1) == LF) {
*p = CR;
Expand Down
112 changes: 112 additions & 0 deletions t/104-req-raw-header.t
Original file line number Diff line number Diff line change
Expand Up @@ -876,3 +876,115 @@ Foo: bar\r
--- no_error_log
[error]
--- timeout: 5



=== TEST 30: large headers(using single LF as line break)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like below.

--- config
location /t {
content_by_lua_block {
ngx.print(ngx.req.raw_header())
}
}

--- raw_request eval
"GET /t HTTP/1.1
Host: localhost
Connection: close
".
(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"

--- response_body eval
qq{GET /t HTTP/1.1
Host: localhost
Connection: close
}
.(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"

--- no_error_log
[error]
--- timeout: 5



=== TEST 31: large headers without request line(using single LF as line break)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better add a space before ( for aesthetic reasons.

--- config
location /t {
content_by_lua_block {
ngx.print(ngx.req.raw_header(true))
}
}

--- raw_request eval
"GET /t HTTP/1.1
Host: localhost
Connection: close
".
(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"

--- response_body eval
qq{Host: localhost
Connection: close
}
.(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"

--- no_error_log
[error]
--- timeout: 5



=== TEST 32: large headers with leading CRLF(using single LF as line break)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

--- config
location /t {
content_by_lua_block {
ngx.print(ngx.req.raw_header())
}
}

--- raw_request eval
"\r
GET /t HTTP/1.1
Host: localhost
Connection: close
".
(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"

--- response_body eval
qq{GET /t HTTP/1.1
Host: localhost
Connection: close
}
.(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"

--- no_error_log
[error]
--- timeout: 5



=== TEST 33: large headers without request line but contains leading CRLF(using single LF as line break)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

--- config
location /t {
content_by_lua_block {
ngx.print(ngx.req.raw_header(true))
}
}

--- raw_request eval
"\r
GET /t HTTP/1.1
Host: localhost
Connection: close
".
(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"

--- response_body eval
qq{Host: localhost
Connection: close
}
.(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"

--- no_error_log
[error]
--- timeout: 5