]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: stats: consider that shared stats pointers may be NULL
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 18 Sep 2025 14:28:29 +0000 (16:28 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 18 Sep 2025 14:49:51 +0000 (16:49 +0200)
commit5c299dee5a1ce6a94ced534891be42345f3e81e5
tree38cf2ebff84aad50e2b8b67cf03cb859c67a243d
parent40eb1dd13545248ce062d704aa894ad288c339b1
MEDIUM: stats: consider that shared stats pointers may be NULL

This patch looks huge, but it has a very simple goal: protect all
accessed to shared stats pointers (either read or writes), because
we know consider that these pointers may be NULL.

The reason behind this is despite all precautions taken to ensure the
pointers shouldn't be NULL when not expected, there are still corner
cases (ie: frontends stats used on a backend which no FE cap and vice
versa) where we could try to access a memory area which is not
allocated. Willy stumbled on such cases while playing with the rings
servers upon connection error, which eventually led to process crashes
(since 3.3 when shared stats were implemented)

Also, we may decide later that shared stats are optional and should
be disabled on the proxy to save memory and CPU, and this patch is
a step further towards that goal.

So in essence, this patch ensures shared stats pointers are always
initialized (including NULL), and adds necessary guards before shared
stats pointers are de-referenced. Since we already had some checks
for backends and listeners stats, and the pointer address retrieval
should stay in cpu cache, let's hope that this patch doesn't impact
stats performance much.
23 files changed:
include/haproxy/backend.h
include/haproxy/counters.h
include/haproxy/proxy.h
include/haproxy/server.h
include/haproxy/stream.h
src/backend.c
src/cache.c
src/check.c
src/fcgi-app.c
src/flt_http_comp.c
src/hlua.c
src/http_act.c
src/http_ana.c
src/listener.c
src/log.c
src/mux_h1.c
src/server.c
src/server_state.c
src/session.c
src/stats-file.c
src/stream.c
src/tcp_act.c
src/tcp_rules.c