Skip to content

Fix posix_getpwnam()/posix_getpwuid() crash on NULL passwd fields#22426

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:posix-passwd-null-fields
Closed

Fix posix_getpwnam()/posix_getpwuid() crash on NULL passwd fields#22426
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:posix-passwd-null-fields

Conversation

@iliaal

@iliaal iliaal commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

php_posix_passwd_to_array() passed pw_name, pw_passwd, pw_gecos, pw_dir and pw_shell straight to add_assoc_string() with no NULL guard, so a NULL string field segfaults the process via zend_string_init(). glibc's files NSS backend normalizes empty fields to the empty string, but third-party NSS modules (nss-systemd, nss-ldap, sssd and other directory backends) populate struct passwd directly and may leave fields NULL. Guard each string field and emit null instead, mirroring the existing handling already present for the group array in php_posix_group_to_array(). A deterministic test needs a non-files NSS backend returning NULL, so there is no portable red/green test; the existing group-path guard is the precedent.

php_posix_passwd_to_array() passed pw_name, pw_passwd, pw_gecos, pw_dir
and pw_shell straight to add_assoc_string() with no NULL guard, so a NULL
field segfaults via zend_string_init(). glibc's files NSS backend
normalizes empty fields to "", but third-party NSS modules (nss-systemd,
nss-ldap, sssd and other directory backends) populate struct passwd
directly and may leave fields NULL. Guard each string field and emit null
instead, mirroring the existing pw/gr handling in php_posix_group_to_array().
@iliaal iliaal closed this in 84d8342 Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants