Skip to content

Fix getusershell() fallback for /etc/shells and array growth - #601

Merged
millert merged 1 commit into
sudo-project:mainfrom
fQwQf:getusershell-fallback
Nov 20, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
fQwQf:getusershell-fallback

Conversation

@fQwQf

@fQwQf fQwQf commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

This fixes the shipped getusershell(3) fallback in lib/util/getusershell.c:

  • The fallback opened /etc/shell instead of /etc/shells (introduced in 034b2f3bd).
  • read_shells() grew allowed_shells with reallocarray(NULL, ...), so after the initial 16 entries the pointers already read were lost and the new array's first slots were left uninitialized.
  • Blank/comment-only lines were stored as empty shell entries and could consume array slots; skip them.

The path fix and the array fix need to stay together. With the typo, /etc/shell normally 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, testsudoers regression test, and SUDO_APPEND_COMPAT_EXP export 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.

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
millert merged commit 082045c into sudo-project:main Nov 20, 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