Skip to content

Commit c25d5d3

Browse files
committed
Fix memory corruption in mkstr caused by integer overflow
The static 'slot' variable in mkstr() was previously a signed 32-bit integer. On high-load systems (e.g., during status data dumps), this counter could overflow, becoming negative. In C, a negative dividend with the modulo operator (slot % 256) results in a negative index. This caused the 'ret' pointer to point to memory addresses BEFORE the actual buffer. In our case, this led to a SIGSEGV because a timestamp string was written directly over the 'contact_list' pointer, which happened to be located in that memory region. Changes: - Changed 'slot' from signed int to unsigned int (uint) to ensure the modulo result is always positive and within buffer bounds. - This ensures that upon reaching UINT_MAX, the counter wraps safely back to zero. Signed-off-by: nook24 <d.ziegler@avendis.com>
1 parent eecfb11 commit c25d5d3

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Breaking changes:
55
Features:
66
* new attribute 'check_timeout' on `host` and `service` structs, overrides the global host / service check timeouts. (#525)
77

8+
Bugfixes:
9+
* fix memory corruption in `mkstr` caused by integer overflow (#527)
10+
811
1.5.0 - Feb 03 2026
912
===================
1013
Breaking changes:

lib/nsutils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ int str2timeval(char *str, struct timeval *tv)
9494
const char *mkstr(const char *fmt, ...)
9595
{
9696
static char buf[MKSTR_BUFS][32]; /* 8k statically on the stack */
97-
static int slot = 0;
97+
static unsigned int slot = 0;
9898
char *ret;
9999

100100
va_list ap;

0 commit comments

Comments
 (0)