Skip to content

Conversation

@Fahnenfluchtige
Copy link
Contributor

The Svace static analysis tool identified a potential issue in the function ngx_stream_lua_req_socket(), where the return value of ngx_stream_lua_get_req is not checked (line 1936):

r = ngx_stream_lua_get_req(L);

The return value of ngx_stream_lua_get_req(L) was used without a null check. But this function (ngx_stream_lua_get_req) is typically checked for NULL in most usages. And moreover, dereferencing a potentially NULL pointer can lead to undefined behavior

So, the solution is to add null-checking:

@@ -1935,6 +1935,10 @@ ngx_stream_lua_req_socket(lua_State *L)
 
     r = ngx_stream_lua_get_req(L);
 
+    if (r == NULL) {
+        return luaL_error(L, "no request found");
+    }

@Fahnenfluchtige Fahnenfluchtige changed the title Fixing deref of null in ngx_stream_lua_util fix: add null check for ngx_stream_lua_get_req in ngx_stream_lua_util Apr 10, 2025
@Fahnenfluchtige Fahnenfluchtige changed the title fix: add null check for ngx_stream_lua_get_req in ngx_stream_lua_util fixes: add null check for ngx_stream_lua_get_req in ngx_stream_lua_util Apr 10, 2025
@zhuizhuhaomeng zhuizhuhaomeng merged commit af6f8c0 into openresty:master Jul 21, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants