From 958a4b696275c24b7cc5beda215bbc243dfcc18e Mon Sep 17 00:00:00 2001 From: Pavel Pautov Date: Thu, 7 Dec 2023 17:41:05 -0800 Subject: [PATCH] Prevent crash for HTTP/0.9 requests (fix #22). --- src/http_module.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/http_module.cpp b/src/http_module.cpp index a8a6ad2..5ebe0a0 100644 --- a/src/http_module.cpp +++ b/src/http_module.cpp @@ -243,7 +243,13 @@ ngx_int_t setHeader(ngx_http_request_t* r, StrView name, StrView value) return NGX_OK; } - header = (ngx_table_elt_t*)ngx_list_push(&r->headers_in.headers); + auto headers = &r->headers_in.headers; + if (!headers->pool && ngx_list_init(headers, r->pool, 2, + sizeof(ngx_table_elt_t)) != NGX_OK) { + return NGX_ERROR; + } + + header = (ngx_table_elt_t*)ngx_list_push(headers); if (header == NULL) { return NGX_ERROR; }