Skip to content

Commit be55be0

Browse files
committed
Fix posix_getgrnam()/posix_getgrgid() crash on NULL group name
php_posix_group_to_array() passed gr_name straight to add_assoc_string() with no NULL guard, so a NULL group name segfaults via zend_string_init(), while the sibling gr_passwd field right below is already guarded. 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 group directly and may leave gr_name NULL. Guard it and emit null instead, matching the existing gr_passwd handling. Closes GH-22433
1 parent c946819 commit be55be0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

ext/posix/posix.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,11 @@ int php_posix_group_to_array(struct group *g, zval *array_group) /* {{{ */
669669

670670
array_init(&array_members);
671671

672-
add_assoc_string(array_group, "name", g->gr_name);
672+
if (g->gr_name) {
673+
add_assoc_string(array_group, "name", g->gr_name);
674+
} else {
675+
add_assoc_null(array_group, "name");
676+
}
673677
if (g->gr_passwd) {
674678
add_assoc_string(array_group, "passwd", g->gr_passwd);
675679
} else {

0 commit comments

Comments
 (0)