From: Aurelien DARRAGON Date: Thu, 19 Feb 2026 13:59:52 +0000 (+0100) Subject: BUG/MINOR: stats-file: manipulate shm-stats-file heartbeat using unsigned int X-Git-Tag: v3.4-dev5~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b7849fd027525c6c6c536753dfe76323bd99735;p=thirdparty%2Fhaproxy.git BUG/MINOR: stats-file: manipulate shm-stats-file heartbeat using unsigned int shm-stats-file heartbeat is derived from now_ms with an extra time added to it, thus it should be handled using the same time as now_ms is. Until now, we used to handle heartbeat using signed integer. This was not found to cause severe harm but it could result in improper handling due to early wrapping because of signedness for instance, so let's better fix that before it becomes a real issue. It should be backported in 3.3 --- diff --git a/include/haproxy/stats-file-t.h b/include/haproxy/stats-file-t.h index a47ddb029..08731326a 100644 --- a/include/haproxy/stats-file-t.h +++ b/include/haproxy/stats-file-t.h @@ -47,7 +47,7 @@ struct shm_stats_file_hdr { */ struct { pid_t pid; - int heartbeat; // last activity of this process + heartbeat timeout, in ticks + uint heartbeat; // last activity of this process + heartbeat timeout, in ticks } slots[64]; int objects; /* actual number of objects stored in the shm */ int objects_slots; /* total available objects slots unless map is resized */ diff --git a/src/stats-file.c b/src/stats-file.c index 99d3a03e8..6942fe45f 100644 --- a/src/stats-file.c +++ b/src/stats-file.c @@ -492,7 +492,7 @@ static int shm_stats_file_check_ver(struct shm_stats_file_hdr *hdr) return 1; } -static inline int shm_hb_is_stale(int hb) +static inline int shm_hb_is_stale(uint hb) { return (hb == TICK_ETERNITY || tick_is_expired(hb, now_ms)); } @@ -501,7 +501,7 @@ static inline int shm_hb_is_stale(int hb) */ static int shm_stats_file_slot_isfree(struct shm_stats_file_hdr *hdr, int id) { - int hb; + uint hb; hb = HA_ATOMIC_LOAD(&hdr->slots[id].heartbeat); return shm_hb_is_stale(hb); @@ -513,7 +513,7 @@ static int shm_stats_file_slot_isfree(struct shm_stats_file_hdr *hdr, int id) int shm_stats_file_get_free_slot(struct shm_stats_file_hdr *hdr) { int it = 0; - int hb; + uint hb; while (it < sizeof(hdr->slots) / sizeof(hdr->slots[0])) { hb = HA_ATOMIC_LOAD(&hdr->slots[it].heartbeat);