Repository navigation
Terminate substituted tokens within the caller buffer - #114
Merged
tillkamppeter merged 1 commit intoNov 19, 2026
Merged
tillkamppeter merged 1 commit into
tillkamppeter merged 1 commit into
Conversation
get_token() substitutes a #define'd variable's value into the current token with strncpy(), but strncpy() does not add a terminating NUL when the source is at least as long as the number of bytes copied. Once that happens the following strlen() walks off the end of the caller's buffer (some of which, like get_po()'s 32-byte locale name, are much smaller than the 1024 bytes a variable's value can hold), and the unconditional NUL write at the end of get_token() then lands outside the buffer too. Switch to snprintf(), which always leaves the destination properly terminated, matching what the "undefined variable" branch right below it already does.
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.
get_token substitutes a variable value with strncpy, which may leave the destination unterminated when the value fills the available space. The following strlen and terminator write can then run beyond the caller buffer. Use snprintf so the substitution is bounded and terminated.