Skip to content

Cleanup php_posix_passwd_to_array() #18496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,12 +906,9 @@ PHP_FUNCTION(posix_getgrgid)
}
/* }}} */

int php_posix_passwd_to_array(struct passwd *pw, zval *return_value) /* {{{ */
static void php_posix_passwd_to_array(struct passwd *pw, zval *return_value) /* {{{ */
{
if (NULL == pw)
return 0;
if (NULL == return_value || Z_TYPE_P(return_value) != IS_ARRAY)
return 0;
ZEND_ASSERT(Z_TYPE_P(return_value) == IS_ARRAY);

add_assoc_string(return_value, "name", pw->pw_name);
add_assoc_string(return_value, "passwd", pw->pw_passwd);
Expand All @@ -920,7 +917,6 @@ int php_posix_passwd_to_array(struct passwd *pw, zval *return_value) /* {{{ */
add_assoc_string(return_value, "gecos", pw->pw_gecos);
add_assoc_string(return_value, "dir", pw->pw_dir);
add_assoc_string(return_value, "shell", pw->pw_shell);
return 1;
}
/* }}} */

Expand Down Expand Up @@ -973,11 +969,7 @@ PHP_FUNCTION(posix_getpwnam)
#endif
array_init(return_value);

if (!php_posix_passwd_to_array(pw, return_value)) {
zend_array_destroy(Z_ARR_P(return_value));
php_error_docref(NULL, E_WARNING, "Unable to convert posix passwd struct to array");
RETVAL_FALSE;
}
php_posix_passwd_to_array(pw, return_value);
#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R)
efree(buf);
#endif
Expand Down Expand Up @@ -1033,11 +1025,7 @@ PHP_FUNCTION(posix_getpwuid)
#endif
array_init(return_value);

if (!php_posix_passwd_to_array(pw, return_value)) {
zend_array_destroy(Z_ARR_P(return_value));
php_error_docref(NULL, E_WARNING, "Unable to convert posix passwd struct to array");
RETVAL_FALSE;
}
php_posix_passwd_to_array(pw, return_value);
#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWUID_R)
efree(pwbuf);
#endif
Expand Down