Skip to content

fixes: add null check for ngx_stream_lua_get_req in ngx_stream_lua_util #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Fahnenfluchtige
Copy link

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
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.

1 participant