Skip to content

os_init_common: always copy envp, even when it is empty - #604

Merged
millert merged 1 commit into
sudo-project:mainfrom
viceice:viceice/fix/empty-envp-copy
Nov 23, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
viceice:viceice/fix/empty-envp-copy

Conversation

@viceice

@viceice viceice commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Since 194042b ("Copy envp -> submit_envp instead of replacing the environ pointer."), os_init_common() only allocates submit_envp when the environment is not empty. With an empty environment it stays NULL, and the plugins get a NULL envp: sudoers.so then crashes with a NULL pointer dereference.

Reproducer (sudo 1.9.18 from main, Debian 13):

env -i /usr/bin/sudo true   # Segmentation fault, exit 139

Drafted by Claude Code (Claude Opus 5.5, low effort) on behalf of @viceice.

Since 194042b, submit_envp is only allocated when the environment
is not empty.  With an empty environment (e.g. "env -i sudo true")
it stays NULL and the plugins get a NULL envp, which makes sudoers.so
crash with a NULL pointer dereference.  Allocate the copy
unconditionally so plugins always get a NULL-terminated array.

Co-Authored-By: Claude Opus 5.5 <michael.kriese+claude-code@gmx.de>

@millert millert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good, thanks for finding the source of the problem.

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