File tree Expand file tree Collapse file tree 2 files changed +115
-4
lines changed
Expand file tree Collapse file tree 2 files changed +115
-4
lines changed Original file line number Diff line number Diff line change @@ -245,7 +245,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
245245
246246 if (b != mr -> header_in ) {
247247 /* skip truncated header entries (if any) */
248- while (last > data && last [-1 ] != LF ) {
248+ while (last > data && last [-1 ] != LF && last [ -1 ] != '\0' ) {
249249 last -- ;
250250 }
251251 }
@@ -315,7 +315,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
315315
316316#if 1
317317 /* skip truncated header entries (if any) */
318- while (last > p && last [-1 ] != LF ) {
318+ while (last > p && last [-1 ] != LF && last [ -1 ] != '\0' ) {
319319 last -- ;
320320 }
321321#endif
@@ -325,8 +325,7 @@ ngx_http_lua_ngx_req_raw_header(lua_State *L)
325325 if (* p == '\0' ) {
326326 j ++ ;
327327 if (p + 1 == last ) {
328- /* XXX this should not happen */
329- dd ("found string end!!" );
328+ * p = LF ;
330329
331330 } else if (* (p + 1 ) == LF ) {
332331 * p = CR ;
Original file line number Diff line number Diff line change @@ -876,3 +876,115 @@ Foo: bar\r
876876--- no_error_log
877877[error]
878878--- timeout: 5
879+
880+
881+
882+ === TEST 30: large headers (using single LF as line break)
883+ --- config
884+ location /t {
885+ content_by_lua_block {
886+ ngx.print(ngx.req.raw_header())
887+ }
888+ }
889+
890+ --- raw_request eval
891+ "GET /t HTTP/1.1
892+ Host: localhost
893+ Connection: close
894+ ".
895+ (CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
896+
897+ --- response_body eval
898+ qq{GET /t HTTP/1.1
899+ Host: localhost
900+ Connection: close
901+ }
902+ .(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
903+
904+ --- no_error_log
905+ [error]
906+ --- timeout: 5
907+
908+
909+
910+ === TEST 31: large headers without request line (using single LF as line break)
911+ --- config
912+ location /t {
913+ content_by_lua_block {
914+ ngx.print(ngx.req.raw_header(true))
915+ }
916+ }
917+
918+ --- raw_request eval
919+ "GET /t HTTP/1.1
920+ Host: localhost
921+ Connection: close
922+ ".
923+ (CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
924+
925+ --- response_body eval
926+ qq{Host: localhost
927+ Connection: close
928+ }
929+ .(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
930+
931+ --- no_error_log
932+ [error]
933+ --- timeout: 5
934+
935+
936+
937+ === TEST 32: large headers with leading CRLF (using single LF as line break)
938+ --- config
939+ location /t {
940+ content_by_lua_block {
941+ ngx.print(ngx.req.raw_header())
942+ }
943+ }
944+
945+ --- raw_request eval
946+ "\r
947+ GET /t HTTP/1.1
948+ Host: localhost
949+ Connection: close
950+ ".
951+ (CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
952+
953+ --- response_body eval
954+ qq{GET /t HTTP/1.1
955+ Host: localhost
956+ Connection: close
957+ }
958+ .(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
959+
960+ --- no_error_log
961+ [error]
962+ --- timeout: 5
963+
964+
965+
966+ === TEST 33: large headers without request line but contains leading CRLF (using single LF as line break)
967+ --- config
968+ location /t {
969+ content_by_lua_block {
970+ ngx.print(ngx.req.raw_header(true))
971+ }
972+ }
973+
974+ --- raw_request eval
975+ "\r
976+ GET /t HTTP/1.1
977+ Host: localhost
978+ Connection: close
979+ ".
980+ (CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
981+
982+ --- response_body eval
983+ qq{Host: localhost
984+ Connection: close
985+ }
986+ .(CORE::join "\n", map { "Header$_: value-$_" } 1..512) . "\n\n"
987+
988+ --- no_error_log
989+ [error]
990+ --- timeout: 5
You can’t perform that action at this time.
0 commit comments