From 3adac088492a7e4c837a2bd2e35bf0e15b1e4027 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sat, 26 Sep 2015 17:51:09 +0200 Subject: [PATCH] BUG/MEDIUM: lua: properly set the target on the connection Not having the target set on the connection causes it to be released at the last moment, and the destination address to randomly be valid depending on the data found in the memory at this moment. In practice it works as long as memory poisonning is disabled. The deep reason is that connect_server() doesn't expect to be called with SF_ADDR_SET and an existing connection with !reuse. This causes the release of the connection, its reallocation (!reuse), and taking the address from the newly allocated connection. This should certainly be improved. --- src/hlua.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hlua.c b/src/hlua.c index d2a2110783..30e294fd04 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -2192,6 +2192,9 @@ __LJMP static int hlua_socket_connect(struct lua_State *L) if (!conn) WILL_LJMP(luaL_error(L, "connect: internal error")); + /* needed for the connection not to be closed */ + conn->target = socket->s->target; + /* Parse ip address. */ conn->addr.to.ss_family = AF_UNSPEC; if (!str2ip2(ip, &conn->addr.to, 0)) -- 2.47.3