- Fix crash when chown() 2nd parameter is something else than integer or string

This commit is contained in:
Jani Taskinen 2007-11-21 11:28:26 +00:00
parent c1c404efc0
commit ba1e024895

View file

@ -434,7 +434,8 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */
if (Z_TYPE_P(group) == IS_LONG) { if (Z_TYPE_P(group) == IS_LONG) {
gid = (gid_t)Z_LVAL_P(group); gid = (gid_t)Z_LVAL_P(group);
} else if (Z_TYPE_P(group) == IS_STRING || } else if (Z_TYPE_P(group) == IS_STRING ||
Z_TYPE_P(group) == IS_UNICODE) { Z_TYPE_P(group) == IS_UNICODE
) {
if (Z_TYPE_P(group) == IS_UNICODE) { if (Z_TYPE_P(group) == IS_UNICODE) {
zval_unicode_to_string(group TSRMLS_CC); zval_unicode_to_string(group TSRMLS_CC);
} }
@ -549,7 +550,12 @@ static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */
if (Z_TYPE_P(user) == IS_LONG) { if (Z_TYPE_P(user) == IS_LONG) {
uid = (uid_t) Z_LVAL_P(user); uid = (uid_t) Z_LVAL_P(user);
} else { } else if (Z_TYPE_P(user) == IS_STRING ||
Z_TYPE_P(user) == IS_UNICODE
) {
if (Z_TYPE_P(user) == IS_UNICODE) {
zval_unicode_to_string(user TSRMLS_CC);
}
#if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R) #if defined(ZTS) && defined(_SC_GETPW_R_SIZE_MAX) && defined(HAVE_GETPWNAM_R)
struct passwd pw; struct passwd pw;
struct passwd *retpwptr = NULL; struct passwd *retpwptr = NULL;
@ -577,6 +583,9 @@ static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */
} }
uid = pw->pw_uid; uid = pw->pw_uid;
#endif #endif
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(user));
RETURN_FALSE;
} }
if (filename_type == IS_UNICODE) { if (filename_type == IS_UNICODE) {