Skip to content

Prevent integer underflow when truncating vlist string#4

Closed
jaredmauch wants to merge 1 commit intofutatuki:mainfrom
jaredmauch:fix/libut-integer-underflow-vlistlen
Closed

Prevent integer underflow when truncating vlist string#4
jaredmauch wants to merge 1 commit intofutatuki:mainfrom
jaredmauch:fix/libut-integer-underflow-vlistlen

Conversation

@jaredmauch
Copy link

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.

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.
{
vlist[vlistlen - 1] = '\0';
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@futatuki
Copy link
Owner

My conclusion is that this check is redundant and is not needed if NULL check for p is added (by PR #3). Close.

@futatuki futatuki closed this Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants