]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: proxy/session: Be sure to have a listener to increment its counters
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 12 Mar 2021 08:16:27 +0000 (09:16 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 12 Mar 2021 08:25:45 +0000 (09:25 +0100)
It is possible to have a session without a listener. It happens for applets
on the client side. Thus all accesses to the listener info from the session
must be guarded. It was the purpose of the commit 36119de18 ("BUG/MEDIUM:
session: NULL dereference possible when accessing the listener"). However,
some tests on the session's listener existence are missing in proxy_inc_*
functions.

This patch should fix the issues #1171, #1172, #1173, #1174 and #1175. It
must be backported with the above commit as far as 1.8.

include/haproxy/proxy.h

index 4488b6965366e95d4e54fc3056369274f51dfc51..69cde1df53301d21d1109d78ac859f670004d30a 100644 (file)
@@ -117,7 +117,7 @@ static inline void proxy_reset_timeouts(struct proxy *proxy)
 static inline void proxy_inc_fe_conn_ctr(struct listener *l, struct proxy *fe)
 {
        _HA_ATOMIC_ADD(&fe->fe_counters.cum_conn, 1);
-       if (l->counters)
+       if (l && l->counters)
                _HA_ATOMIC_ADD(&l->counters->cum_conn, 1);
        HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.cps_max,
                             update_freq_ctr(&fe->fe_conn_per_sec, 1));
@@ -128,7 +128,7 @@ static inline void proxy_inc_fe_sess_ctr(struct listener *l, struct proxy *fe)
 {
 
        _HA_ATOMIC_ADD(&fe->fe_counters.cum_sess, 1);
-       if (l->counters)
+       if (l && l->counters)
                _HA_ATOMIC_ADD(&l->counters->cum_sess, 1);
        HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.sps_max,
                             update_freq_ctr(&fe->fe_sess_per_sec, 1));
@@ -146,7 +146,7 @@ static inline void proxy_inc_be_ctr(struct proxy *be)
 static inline void proxy_inc_fe_req_ctr(struct listener *l, struct proxy *fe)
 {
        _HA_ATOMIC_ADD(&fe->fe_counters.p.http.cum_req, 1);
-       if (l->counters)
+       if (l && l->counters)
                _HA_ATOMIC_ADD(&l->counters->p.http.cum_req, 1);
        HA_ATOMIC_UPDATE_MAX(&fe->fe_counters.p.http.rps_max,
                             update_freq_ctr(&fe->fe_req_per_sec, 1));