From c8c0c372bcdfdc5547d03aebe06e48679da0496b Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Wed, 5 Mar 2025 17:55:23 +0800 Subject: [PATCH 1/2] feature: add function to bypass HTTP conditional request checks I hereby granted the copyright of the changes in this pull request to the authors of this lua-nginx-module project. releated: https://github.com/openresty/lua-nginx-module/issues/2397 refer: https://github.com/nginx/nginx/commit/d9887ee2ae9069843eed67d5b5ea625a7faeedb1 Signed-off-by: tzssangglass --- src/ngx_http_lua_util.c | 7 +++++++ t/014-bugs.t | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/ngx_http_lua_util.c b/src/ngx_http_lua_util.c index c73bddc609..02dfab29d9 100644 --- a/src/ngx_http_lua_util.c +++ b/src/ngx_http_lua_util.c @@ -4555,4 +4555,11 @@ ngx_http_lua_parse_addr(lua_State *L, u_char *text, size_t len) } +int +ngx_http_lua_ffi_bypass_if_checks(ngx_http_request_t *r) +{ + r->disable_not_modified = 1; + return NGX_OK; +} + /* vi:set ft=c ts=4 sw=4 et fdm=marker: */ diff --git a/t/014-bugs.t b/t/014-bugs.t index 303187929f..9d57afe134 100644 --- a/t/014-bugs.t +++ b/t/014-bugs.t @@ -1366,3 +1366,33 @@ If-Match: 1 --- error_code: 412 --- response_body eval qr/\Ahello\z/ + + + +=== TEST 50: nginx crashes when encountering an illegal http if header +crash with ngx.print() +--- main_config +--- config +error_page 412 /my_error_handler_412; + +location /t { + access_by_lua_block { + local ngx_resp = require "ngx.resp" + ngx_resp.bypass_if_checks() + ngx.print("hello") + ngx.exit(200) + } +} +location = /my_error_handler_412 { + content_by_lua_block { + ngx.sleep(0.002) + ngx.header["Content-Type"] = "text/plain" + } +} +--- request + GET /t +--- more_headers +If-Match: 1 +--- error_code: 200 +--- response_body eval +qr/\Ahello\z/ From 13db46466bfdf33a2a88e6102f6781bf23910e7c Mon Sep 17 00:00:00 2001 From: tzssangglass Date: Fri, 7 Mar 2025 18:15:10 +0800 Subject: [PATCH 2/2] refactor: modify bypass_if_checks function to return void Signed-off-by: tzssangglass --- src/ngx_http_lua_util.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ngx_http_lua_util.c b/src/ngx_http_lua_util.c index 02dfab29d9..61f56cb7c0 100644 --- a/src/ngx_http_lua_util.c +++ b/src/ngx_http_lua_util.c @@ -4555,11 +4555,10 @@ ngx_http_lua_parse_addr(lua_State *L, u_char *text, size_t len) } -int +void ngx_http_lua_ffi_bypass_if_checks(ngx_http_request_t *r) { r->disable_not_modified = 1; - return NGX_OK; } /* vi:set ft=c ts=4 sw=4 et fdm=marker: */