From aef60ebf9868af83ab80bf542036bc3c173f06a3 Mon Sep 17 00:00:00 2001 From: oxpa Date: Thu, 6 Apr 2023 14:20:52 +0100 Subject: [PATCH 1/4] Properly initialize list elements --- src/ngx_http_lua_control.c | 1 + src/ngx_http_lua_headers_in.c | 1 + src/ngx_http_lua_headers_out.c | 2 ++ 3 files changed, 4 insertions(+) diff --git a/src/ngx_http_lua_control.c b/src/ngx_http_lua_control.c index 99460456c1..72b67b7813 100644 --- a/src/ngx_http_lua_control.c +++ b/src/ngx_http_lua_control.c @@ -280,6 +280,7 @@ ngx_http_lua_ngx_redirect(lua_State *L) h->value.len = len; h->value.data = uri; + h->next = NULL; ngx_str_set(&h->key, "Location"); r->headers_out.status = rc; diff --git a/src/ngx_http_lua_headers_in.c b/src/ngx_http_lua_headers_in.c index 4405481408..50c062d49e 100644 --- a/src/ngx_http_lua_headers_in.c +++ b/src/ngx_http_lua_headers_in.c @@ -280,6 +280,7 @@ ngx_http_set_header_helper(ngx_http_request_t *r, ngx_http_lua_header_val_t *hv, h->key = hv->key; h->value = *value; + h->next = NULL; h->lowcase_key = ngx_pnalloc(r->pool, h->key.len); if (h->lowcase_key == NULL) { diff --git a/src/ngx_http_lua_headers_out.c b/src/ngx_http_lua_headers_out.c index 571723d9a6..5f858ec99a 100644 --- a/src/ngx_http_lua_headers_out.c +++ b/src/ngx_http_lua_headers_out.c @@ -229,6 +229,7 @@ ngx_http_set_header_helper(ngx_http_request_t *r, ngx_http_lua_header_val_t *hv, h->key = hv->key; h->value = *value; + h->next = NULL; h->lowcase_key = ngx_pnalloc(r->pool, h->key.len); if (h->lowcase_key == NULL) { @@ -444,6 +445,7 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r, } ho->key = hv->key; + ho->next = NULL; *ph = ho; return NGX_OK; From 17823429346379c48698fd35c834e4f80ea5fe4e Mon Sep 17 00:00:00 2001 From: oxpa Date: Thu, 6 Apr 2023 14:43:56 +0100 Subject: [PATCH 2/4] Improve test to detect improper header list handling --- t/020-subrequest.t | 1 + t/111-req-header-ua.t | 2 ++ 2 files changed, 3 insertions(+) diff --git a/t/020-subrequest.t b/t/020-subrequest.t index 844b64794f..0b4da7ee80 100644 --- a/t/020-subrequest.t +++ b/t/020-subrequest.t @@ -13,6 +13,7 @@ repeat_each(2); plan tests => repeat_each() * (blocks() * 3 + 23); +$ENV{MALLOC_PERTURB_} = 9; $ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211; $ENV{TEST_NGINX_HTML_DIR} ||= html_dir(); diff --git a/t/111-req-header-ua.t b/t/111-req-header-ua.t index 9e501e3c08..5b9133960d 100644 --- a/t/111-req-header-ua.t +++ b/t/111-req-header-ua.t @@ -10,6 +10,8 @@ repeat_each(2); plan tests => repeat_each() * (4 * blocks()); +$ENV{MALLOC_PERTURB_} = 9; + #no_diff(); no_long_string(); From def29fb06c53644aa28e064fc664968538b98929 Mon Sep 17 00:00:00 2001 From: oxpa Date: Thu, 6 Apr 2023 16:02:06 +0100 Subject: [PATCH 3/4] move common test env into the CI config --- .travis.yml | 1 + t/020-subrequest.t | 1 - t/111-req-header-ua.t | 2 -- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1a051b7120..64d27d8529 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,6 +50,7 @@ env: - LD_LIBRARY_PATH=$LUAJIT_LIB:$LD_LIBRARY_PATH - DRIZZLE_VER=2011.07.21 - TEST_NGINX_SLEEP=0.006 + - MALLOC_PERTURB_=9 jobs: - NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.0l OPENSSL_PATCH_VER=1.1.0d - NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1s OPENSSL_PATCH_VER=1.1.1f diff --git a/t/020-subrequest.t b/t/020-subrequest.t index 0b4da7ee80..844b64794f 100644 --- a/t/020-subrequest.t +++ b/t/020-subrequest.t @@ -13,7 +13,6 @@ repeat_each(2); plan tests => repeat_each() * (blocks() * 3 + 23); -$ENV{MALLOC_PERTURB_} = 9; $ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211; $ENV{TEST_NGINX_HTML_DIR} ||= html_dir(); diff --git a/t/111-req-header-ua.t b/t/111-req-header-ua.t index 5b9133960d..9e501e3c08 100644 --- a/t/111-req-header-ua.t +++ b/t/111-req-header-ua.t @@ -10,8 +10,6 @@ repeat_each(2); plan tests => repeat_each() * (4 * blocks()); -$ENV{MALLOC_PERTURB_} = 9; - #no_diff(); no_long_string(); From 2080eea43d20bae3c9a95628fba4070f981c3ae0 Mon Sep 17 00:00:00 2001 From: oxpa Date: Thu, 6 Apr 2023 18:46:41 +0100 Subject: [PATCH 4/4] Wrap ngx_table_elt_t operations into version checks --- src/ngx_http_lua_control.c | 2 ++ src/ngx_http_lua_headers_in.c | 2 ++ src/ngx_http_lua_headers_out.c | 3 ++- src/ngx_http_lua_subrequest.c | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ngx_http_lua_control.c b/src/ngx_http_lua_control.c index 72b67b7813..d7e427385d 100644 --- a/src/ngx_http_lua_control.c +++ b/src/ngx_http_lua_control.c @@ -280,7 +280,9 @@ ngx_http_lua_ngx_redirect(lua_State *L) h->value.len = len; h->value.data = uri; +#if defined(nginx_version) && nginx_version >= 1023000 h->next = NULL; +#endif ngx_str_set(&h->key, "Location"); r->headers_out.status = rc; diff --git a/src/ngx_http_lua_headers_in.c b/src/ngx_http_lua_headers_in.c index 50c062d49e..960e2f85f6 100644 --- a/src/ngx_http_lua_headers_in.c +++ b/src/ngx_http_lua_headers_in.c @@ -280,7 +280,9 @@ ngx_http_set_header_helper(ngx_http_request_t *r, ngx_http_lua_header_val_t *hv, h->key = hv->key; h->value = *value; +#if defined(nginx_version) && nginx_version >= 1023000 h->next = NULL; +#endif h->lowcase_key = ngx_pnalloc(r->pool, h->key.len); if (h->lowcase_key == NULL) { diff --git a/src/ngx_http_lua_headers_out.c b/src/ngx_http_lua_headers_out.c index 5f858ec99a..c51146a3fc 100644 --- a/src/ngx_http_lua_headers_out.c +++ b/src/ngx_http_lua_headers_out.c @@ -229,7 +229,9 @@ ngx_http_set_header_helper(ngx_http_request_t *r, ngx_http_lua_header_val_t *hv, h->key = hv->key; h->value = *value; +#if defined(nginx_version) && nginx_version >= 1023000 h->next = NULL; +#endif h->lowcase_key = ngx_pnalloc(r->pool, h->key.len); if (h->lowcase_key == NULL) { @@ -445,7 +447,6 @@ ngx_http_set_builtin_multi_header(ngx_http_request_t *r, } ho->key = hv->key; - ho->next = NULL; *ph = ho; return NGX_OK; diff --git a/src/ngx_http_lua_subrequest.c b/src/ngx_http_lua_subrequest.c index f6638c2991..c09207417e 100644 --- a/src/ngx_http_lua_subrequest.c +++ b/src/ngx_http_lua_subrequest.c @@ -1667,6 +1667,9 @@ ngx_http_lua_copy_request_headers(ngx_http_request_t *sr, clh->hash = ngx_http_lua_content_length_hash; clh->key = ngx_http_lua_content_length_header_key; +#if defined(nginx_version) && nginx_version >= 1023000 + clh->next = NULL; +#endif clh->lowcase_key = ngx_pnalloc(sr->pool, clh->key.len); if (clh->lowcase_key == NULL) { return NGX_ERROR;