BUG/MINOR: session: ensure conn owner is set after insert into session

A crash could occured if a session_add_conn() would temporarily failed
when called via h2_detach(). In this case, connection owner is reset to
NULL. However, if this wasn't the last connection stream, the connection
won't be destroyed. When h2_detach() is recalled for another stream and
this time session_add_conn() succeeds, a crash will occur due to
session_check_idle_conn() invocation with a NULL connection owner.

To fix this, ensure connection owner is always set after
session_add_conn() success.

This bug is considered as minor as the only failure reason for
session_add_conn() is a pool allocation issue.

This should be backported up to all stable releases.

(cherry picked from commit c130f74803bc8bb40a748f734b7e150b3a23daa7)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit f37820431cfb09733331b546c47d1345bc38a058)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit cd3916efc859e29b18d84be56718c2ca6d26ceba)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 138afe3a1feb59a5b77408951124ee01223141b8)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 1e59bf601d3f932280b3d9c7ddbf950f0df2e0ca)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/include/haproxy/session.h b/include/haproxy/session.h
index 1842b7a..acf2d89 100644
--- a/include/haproxy/session.h
+++ b/include/haproxy/session.h
@@ -175,6 +175,12 @@
 		LIST_APPEND(&sess->srv_list, &srv_list->srv_list);
 	}
 	LIST_APPEND(&srv_list->conn_list, &conn->session_list);
+
+	/* Ensure owner is set for connection. It could have been resetted
+	 * prior on after a session_add_conn() failure.
+	 */
+	conn->owner = sess;
+
 	return 1;
 }