Skip to content

Commit 0a2d1d2

Browse files
committed
bugfix: udpsock:send() might crash on null pointer access when the request object is absent or the u pointer is null.
1 parent 4ae7d6a commit 0a2d1d2

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ngx_http_lua_socket_udp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,18 @@ ngx_http_lua_socket_udp_send(lua_State *L)
673673
r = lua_touserdata(L, -1);
674674
lua_pop(L, 1);
675675

676+
if (r == NULL) {
677+
return luaL_error(L, "request object not found");
678+
}
679+
676680
luaL_checktype(L, 1, LUA_TTABLE);
677681

678682
lua_rawgeti(L, 1, SOCKET_CTX_INDEX);
679683
u = lua_touserdata(L, -1);
680684
lua_pop(L, 1);
681685

682686
if (u == NULL || u->udp_connection.connection == NULL || u->ft_type) {
683-
ngx_log_error(NGX_LOG_ERR, &u->udp_connection.log, 0,
687+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
684688
"attempt to send data on a closed socket: u:%p, c:%p, "
685689
"ft:%ui",
686690
u, u ? u->udp_connection.connection : NULL,

0 commit comments

Comments
 (0)