Prevent integer underflow when truncating vlist string#4
Closed
jaredmauch wants to merge 1 commit intofutatuki:mainfrom
Closed
Prevent integer underflow when truncating vlist string#4jaredmauch wants to merge 1 commit intofutatuki:mainfrom
jaredmauch wants to merge 1 commit intofutatuki:mainfrom
Conversation
The code accesses vlist[vlistlen - 1] without checking if vlistlen > 0. If vlistlen is 0 (due to decrements in the switch statement), then vlistlen - 1 would underflow to SIZE_MAX (since vlistlen is size_t), causing a massive buffer overflow. Fix by checking that vlistlen > 0 and that vlistlen is within the actual string bounds before accessing vlist[vlistlen - 1]. This prevents both integer underflow and buffer overflow vulnerabilities. This complements the upstream fix for the buffer overflow issue by adding explicit bounds checking.
futatuki
reviewed
Dec 23, 2025
| { | ||
| vlist[vlistlen - 1] = '\0'; | ||
| } | ||
|
|
Owner
There was a problem hiding this comment.
vlistlen here always >= 1 because p should be NULL terminated string and *p points other than \0 (} is not found while scanning). And then vlist is never never truncated as I wrote the comment on PR #3, I think.
Owner
|
My conclusion is that this check is redundant and is not needed if |
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.
The code accesses vlist[vlistlen - 1] without checking if vlistlen > 0. If vlistlen is 0 (due to decrements in the switch statement), then vlistlen - 1 would underflow to SIZE_MAX (since vlistlen is size_t), causing a buffer overflow.
Fix by checking that vlistlen > 0 and that vlistlen is within the actual string bounds before accessing vlist[vlistlen - 1]. This prevents both integer underflow and buffer overflow vulnerabilities.