openresty / lua-nginx-module

Embed the Power of Lua into NGINX HTTP servers
https://openresty.org/
11.33k stars 2.03k forks source link

unreachable code in ngx_http_lua_util #2359

Closed leeriorio closed 2 months ago

leeriorio commented 2 months ago

In result of static analyse of nginx source code (including lua-nginx-module) with Svace static analyzer I found error of cathegory "UNREACHABLE_CODE" (checker finds source code that can't be executed) in ngx_http_lua_util.c

this minor error affects ngx_http_lua_send_http10_headers() function in lines 761-771 of ngx_http_lua_util.c

760
761    if (r->headers_out.content_length == NULL) {
762        for (size = 0, cl = ctx->out; cl; cl = cl->next) {
763            size += ngx_buf_size(cl->buf);
764        }
765
766        r->headers_out.content_length_n = size;
767
768        if (r->headers_out.content_length) {
769            r->headers_out.content_length->hash = 0;
770        }
771    }
772

https://github.com/openresty/lua-nginx-module/blob/master/src/ngx_http_lua_util.c#L761-L771

line 769 is unreachable because it's condition (r->headers_out.content_length) not compliant to context condition in line 761 (r->headers_out.content_length == NULL). How about to review this code area?

zhuizhuhaomeng commented 2 months ago

fixed in https://github.com/openresty/lua-nginx-module/commit/dfeaab4fdac09e1056873c920c42d70f99342777