Skip to content

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

Open
iliaal wants to merge 1 commit into
PHP-8.4from
posix-passwd-null-fields
Open

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

Conversation

@iliaal

@iliaal iliaal commented Jun 21, 2026

Copy link
Copy Markdown
Owner

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().
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.

1 participant