Skip to content

Remove tv_str and use a unsigned int for slot in mkstr#526

Closed
nook24 wants to merge 2 commits intomasterfrom
remove_tv_str
Closed

Remove tv_str and use a unsigned int for slot in mkstr#526
nook24 wants to merge 2 commits intomasterfrom
remove_tv_str

Conversation

@nook24
Copy link
Copy Markdown
Member

@nook24 nook24 commented Mar 16, 2026

We have noticed random segfaults on one of our systems during the creating of status.dat.
Since Naemon 1.5.0, tv_str is called in the For-loop for each host and service status object, which will increase the counter of slot by one each time. After 2.147.483.647 the integer will flip into -2.147.483.648 and modulo of a negativ dividend will result in a negativ value in C (and PHP, Go JavaScript).
When reading buf[-2147468803] whatever is at this address will be overwritten.

nook24 added 2 commits March 16, 2026 13:56
…will increase slot++ in mkstr

Signed-off-by: nook24 <d.ziegler@avendis.com>
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>
@nook24
Copy link
Copy Markdown
Member Author

nook24 commented Mar 17, 2026

Please see #527

@nook24 nook24 closed this Mar 17, 2026
@nook24 nook24 deleted the remove_tv_str branch March 23, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant