From: Jani Taskinen Date: Wed, 21 Nov 2007 11:28:26 +0000 (+0000) Subject: - Fix crash when chown() 2nd parameter is something else than integer or string X-Git-Tag: RELEASE_2_0_0a1~1318 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ba1e024895e256c51a3fa61ad6b797b9481ef2a8;p=php - Fix crash when chown() 2nd parameter is something else than integer or string --- diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 7797705ed7..34e622a1cb 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -434,7 +434,8 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */ if (Z_TYPE_P(group) == IS_LONG) { gid = (gid_t)Z_LVAL_P(group); } 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) { zval_unicode_to_string(group TSRMLS_CC); } @@ -466,7 +467,7 @@ static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp) /* {{{ */ gid = gr->gr_gid; #endif } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given",zend_zval_type_name(group)); + php_error_docref(NULL TSRMLS_CC, E_WARNING, "parameter 2 should be string or integer, %s given", zend_zval_type_name(group)); RETURN_FALSE; } @@ -548,8 +549,13 @@ static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */ } if (Z_TYPE_P(user) == IS_LONG) { - uid = (uid_t)Z_LVAL_P(user); - } else { + uid = (uid_t) Z_LVAL_P(user); + } 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) struct passwd pw; struct passwd *retpwptr = NULL; @@ -577,6 +583,9 @@ static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown) /* {{{ */ } uid = pw->pw_uid; #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) {