Remove tv_str and use a unsigned int for slot in mkstr#526
Closed
Remove tv_str and use a unsigned int for slot in mkstr#526
Conversation
…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>
Member
Author
|
Please see #527 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have noticed random segfaults on one of our systems during the creating of
status.dat.Since Naemon 1.5.0,
tv_stris called in the For-loop for each host and service status object, which will increase the counter ofslotby 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.