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 d2a2110..30e294f 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2192,6 +2192,9 @@
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))