MINOR: hlua: Don't preform operations on a not connected socket

There is nothing that prevent someone to create a lua socket and try to
receive or to write before the connection was established ot after the
shutdown was performed. The same is true when info about the socket are
retrieved.

It is not an issue because this will fail later. But now, we check the
socket is connected or not earlier. It is more effecient but it will be also
mandatory to fix issue with the lua sockets.
This commit is contained in:
Christopher Faulet 2023-09-27 17:22:41 +02:00
parent ed9333827a
commit ee687aa18d
1 changed files with 27 additions and 2 deletions

View File

@ -2496,6 +2496,9 @@ __LJMP static int hlua_socket_receive_yield(struct lua_State *L, int status, lua
goto no_peer;
csk_ctx = container_of(peer, struct hlua_csk_ctx, xref);
if (!csk_ctx->connected)
goto connection_closed;
appctx = csk_ctx->appctx;
s = appctx_strm(appctx);
@ -2737,6 +2740,12 @@ static int hlua_socket_write_yield(struct lua_State *L,int status, lua_KContext
}
csk_ctx = container_of(peer, struct hlua_csk_ctx, xref);
if (!csk_ctx->connected) {
xref_unlock(&socket->xref, peer);
lua_pushinteger(L, -1);
return 1;
}
appctx = csk_ctx->appctx;
sc = appctx_sc(appctx);
s = __sc_strm(sc);
@ -2946,6 +2955,7 @@ __LJMP static int hlua_socket_getpeername(struct lua_State *L)
{
struct hlua_socket *socket;
struct xref *peer;
struct hlua_csk_ctx *csk_ctx;
struct appctx *appctx;
struct stconn *sc;
const struct sockaddr_storage *dst;
@ -2968,7 +2978,14 @@ __LJMP static int hlua_socket_getpeername(struct lua_State *L)
return 1;
}
appctx = container_of(peer, struct hlua_csk_ctx, xref)->appctx;
csk_ctx = container_of(peer, struct hlua_csk_ctx, xref);
if (!csk_ctx->connected) {
xref_unlock(&socket->xref, peer);
lua_pushnil(L);
return 1;
}
appctx = csk_ctx->appctx;
sc = appctx_sc(appctx);
dst = sc_dst(sc_opposite(sc));
if (!dst) {
@ -2989,6 +3006,7 @@ static int hlua_socket_getsockname(struct lua_State *L)
struct connection *conn;
struct appctx *appctx;
struct xref *peer;
struct hlua_csk_ctx *csk_ctx;
struct stream *s;
int ret;
@ -3009,7 +3027,14 @@ static int hlua_socket_getsockname(struct lua_State *L)
return 1;
}
appctx = container_of(peer, struct hlua_csk_ctx, xref)->appctx;
csk_ctx = container_of(peer, struct hlua_csk_ctx, xref);
if (!csk_ctx->connected) {
xref_unlock(&socket->xref, peer);
lua_pushnil(L);
return 1;
}
appctx = csk_ctx->appctx;
s = appctx_strm(appctx);
conn = sc_conn(s->scb);