Repository navigation
Fix getusershell() fallback for /etc/shells and array growth - #601
Merged
Merged
Conversation
The getusershell() compatibility implementation read /etc/shell instead of /etc/shells. It also expanded the shell array with reallocarray(NULL, ...), discarding the entries read so far once the list grew beyond the initial allocation. Fix both and skip blank or comment-only lines so they do not consume array entries. The path fix must not be applied without the array fix: once the fallback reads /etc/shells, a list with 16 or more entries would otherwise hit the uninitialized slots.
millert
approved these changes
Nov 20, 2026
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.
This fixes the shipped
getusershell(3)fallback inlib/util/getusershell.c:/etc/shellinstead of/etc/shells(introduced in034b2f3bd).read_shells()grewallowed_shellswithreallocarray(NULL, ...), so after the initial 16 entries the pointers already read were lost and the new array's first slots were left uninitialized.The path fix and the array fix need to stay together. With the typo,
/etc/shellnormally does not exist and the fallback returns the built-in list without growing the array; after switching to/etc/shells, a list with 16 or more entries would otherwise hit the uninitialized slots.Given that the fallback is not compiled on modern systems, I kept this change minimal and left out the unit test,
testsudoersregression test, andSUDO_APPEND_COMPAT_EXPexport change; happy to add any of them if you prefer.Tested locally on Debian 13 (gcc 14.2) with a normal build and an ASan build using a local unit test, which aborts on the unfixed code and passes with the fix.