From: Aurelien DARRAGON Date: Tue, 18 Mar 2025 13:22:00 +0000 (+0100) Subject: BUG/MINOR: hlua: fix optional timeout argument index for AppletTCP:receive() X-Git-Tag: v3.2-dev8~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4651c4edd5c32ffd5a2244147b3b7bff20accd5f;p=thirdparty%2Fhaproxy.git BUG/MINOR: hlua: fix optional timeout argument index for AppletTCP:receive() Baptiste reported that using the new optional timeout argument introduced in 19e48f2 ("MINOR: hlua: add an optional timeout to AppletTCP:receive()") the following error would occur at some point: runtime error: file.lua:lineno: bad argument #-2 to 'receive' (number expected, got light userdata) from [C]: in method 'receive... In fact this is caused by exp_date being retrieved using relative index -1 instead of absolute index 3. Indeed, while using relative index is fine most of the time when we trust the stack, when combined with yielding the top of the stack when resuming from yielding is not necessarily the same as when the function was first called (ie: if some data was pushed to the stack in the yieldable function itself). As such, it is safer to use explicit index to access exp_date variable at position 3 on the stack. It was confirmed that doing so addresses the issue. No backport needed unless 19e48f2 is. --- diff --git a/src/hlua.c b/src/hlua.c index 8c58e498d..6d5074e2c 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -5321,7 +5321,7 @@ __LJMP static int hlua_applet_tcp_recv_yield(lua_State *L, int status, lua_KCont struct hlua_appctx *luactx = MAY_LJMP(hlua_checkapplet_tcp(L, 1)); struct stconn *sc = appctx_sc(luactx->appctx); size_t len = MAY_LJMP(luaL_checkinteger(L, 2)); - int exp_date = MAY_LJMP(luaL_checkinteger(L, -1)); + int exp_date = MAY_LJMP(luaL_checkinteger(L, 3)); int ret; const char *blk1; size_t len1;