From: Willy Tarreau Date: Sat, 26 Sep 2015 15:51:09 +0000 (+0200) Subject: BUG/MEDIUM: lua: properly set the target on the connection X-Git-Tag: v1.6-dev6~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3adac088492a7e4c837a2bd2e35bf0e15b1e4027;p=thirdparty%2Fhaproxy.git 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. --- 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))