BUG/MEDIUM: stats: prevent crash if counters not alloc with dummy one
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 10 Nov 2020 13:24:31 +0000 (14:24 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 Nov 2020 14:16:05 +0000 (15:16 +0100)
commit7f8f6cb926f777bc49b24bd783879b288dc390ee
tree3f3ac7ff1cae4c061ba52da02f52ef9606d8cd82
parenta2a6899bee5add180afb02ac2b1ce7cb360a96e3
BUG/MEDIUM: stats: prevent crash if counters not alloc with dummy one

Define a per-thread counters allocated with the greatest size of any
stat module counters. This variable is named trash_counters.

When using a proxy without allocated counters, return the trash counters
from EXTRA_COUNTERS_GET instead of a dangling pointer to prevent
segfault.

This is useful for all the proxies used internally and not
belonging to the global proxy list. As these objects does not appears on
the stat report, it does not matter to use the dummy counters.

For this fix to be functional, the extra counters are explicitly
initialized to NULL on proxy/server/listener init functions.

Most notably, the crash has already been detected with the following
vtc:
- reg-tests/lua/txn_get_priv.vtc
- reg-tests/peers/tls_basic_sync.vtc
- reg-tests/peers/tls_basic_sync_wo_stkt_backend.vtc
There is probably other parts that may be impacted (SPOE for example).

This bug was introduced in the current release and do not need to be
backported. The faulty commits are
"MINOR: ssl: count client hello for stats" and
"MINOR: ssl: add counters for ssl sessions".
include/haproxy/stats-t.h
src/listener.c
src/proxy.c
src/server.c
src/stats.c