Fix out-of-bounds cursor increment in pop_token() - #222
Merged
Conversation
Signed-off-by: yi chen <94xhn1@gmail.com>
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.
While parsing tokens from the configuration file lines (and IPC parameters), \pop_token()\ traverses to the end of a token. When parsing the last token on a line, \end\ will point to the natural null terminator \0. Unconditionally incrementing the cursor *line = end + 1\ makes the next parsing loop reference memory past the buffer boundaries (an out-of-bounds read). If the adjacent memory is dirty (not null or whitespaces), \pop_token\ will process it as a token and write a null terminator *end = 0\ further out-of-bounds. This patch checks if *end == '\0'\ first. If it is, *line\ is safely set to \NULL\ to prevent subsequent parsing loops from running off the buffer. Otherwise, it proceeds with the usual null termination and cursor increment.