Skip to content

sudo_parse_gids: don't write past the array for an empty gid list - #612

Merged
millert merged 1 commit into
sudo-project:mainfrom
iefa-m:parse-gids-empty-list-overflow
Dec 6, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
iefa-m:parse-gids-empty-list-overflow

Conversation

@iefa-m

@iefa-m iefa-m commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Heap out-of-bounds write in sudo_parse_gids() for an empty gid list

The counting pass in sudo_parse_gids_v1() is guarded by if (*cp != '\0'), so an empty gidstr adds nothing to the size, but the pass that fills the array is an unguarded do/while that always runs once. With a non-NULL basegid and an empty gid string the allocation holds a single GETGROUPS_T, gids[0] is the base gid, and the loop then assigns to gids[1], one element past the end, before the sudo_strtoidx() error is noticed and the array is freed.

Guarding the fill loop with the same emptiness test makes an empty list parse to just the base gid. That matches the basegid == NULL case, which already returns 0 for an empty string without entering the block.

sudo_parse_gids() is public in libsudo_util, so any caller that hands it an unvalidated string hits this. sudoers_policy_deserialize_info() is the only caller in the tree that passes a base gid, and its CHECK() macro rejects groups= with an empty value, so the sudoers plugin itself does not reach it today.

The new case in lib/util/regress/parse_gids/parse_gids_test.c covers ("", &basegid): before the fix the out-of-bounds write happens and the parse then fails, so the test exits via sudo_fatal_nodebug(); after it, one gid comes back.

@millert
millert merged commit b93da73 into sudo-project:main Dec 6, 2026
5 checks passed
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