fix potential mem corruption in utils_log_internal#1576
Open
bratpiorka wants to merge 1 commit into
Open
Conversation
15922c5 to
58042b1
Compare
PatKamin
reviewed
May 29, 2026
|
|
||
| b_pos += (int)tmp; | ||
| b_size -= (int)tmp; | ||
| log_buffer_advance(&b_pos, &b_size, tmp); |
Contributor
There was a problem hiding this comment.
Define b_size as size_t to avoid further casting of size_t to int in log_buffer_append(). I think sizeof should already return size_t type number.
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.
Fix potential mem corruption in utils_log_internal(), steps to reproduce:
The root cause is incorrect handling of the return values from
snprintf()andvsnprintf(). These functions return the number of bytes that would have been written if enough space were available. The code unconditionally advancesb_posand reducesb_sizeby that return value, even when truncation occurred.If the first
snprintf()truncates, tmp can be larger than the remaining buffer. This movesb_pospast the end of the stack buffer and makesb_sizeinvalid. The nextvsnprintf()then writes through an invalid destination pointer, causing an out-of-bounds stack write.