From: alexanderholman Date: Fri, 5 Jan 2018 00:42:06 +0000 (+0000) Subject: Fixed bug #74719 X-Git-Tag: php-7.3.0alpha1~598 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a01de10b075de9558dfe27535e601c7c4c0c819e;p=php Fixed bug #74719 Allow stream context arguments for fopen, rename, unlink, mkdir and rmdir to be null. --- diff --git a/NEWS b/NEWS index 6dad61245a..fd1e6104ba 100644 --- a/NEWS +++ b/NEWS @@ -160,10 +160,11 @@ PHP NEWS used). (Anton Artamonov) - Standard: - . Fixed unzserialize(), to disable creation of unsupported data structures + . Fixed unserialize(), to disable creation of unsupported data structures through manually crafted strings. (Dmitry) . Fixed bug #75409 (accept EFAULT in addition to ENOSYS as indicator that getrandom() is missing). (sarciszewski) + . Fixed bug #74719 (fopen() should accept NULL as context). (Alexander Holman) - Testing: . Implemented request #62055 (Make run-tests.php support --CGI-- sections). diff --git a/ext/standard/file.c b/ext/standard/file.c index 9c69874c79..d5b52e0b72 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -883,7 +883,7 @@ PHP_NAMED_FUNCTION(php_if_fopen) Z_PARAM_STRING(mode, mode_len) Z_PARAM_OPTIONAL Z_PARAM_BOOL(use_include_path) - Z_PARAM_RESOURCE(zcontext) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -1346,7 +1346,7 @@ PHP_FUNCTION(mkdir) Z_PARAM_OPTIONAL Z_PARAM_LONG(mode) Z_PARAM_BOOL(recursive) - Z_PARAM_RESOURCE(zcontext) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -1367,7 +1367,7 @@ PHP_FUNCTION(rmdir) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH(dir, dir_len) Z_PARAM_OPTIONAL - Z_PARAM_RESOURCE(zcontext) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -1469,7 +1469,7 @@ PHP_FUNCTION(rename) Z_PARAM_PATH(old_name, old_name_len) Z_PARAM_PATH(new_name, new_name_len) Z_PARAM_OPTIONAL - Z_PARAM_RESOURCE(zcontext) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); wrapper = php_stream_locate_url_wrapper(old_name, NULL, 0); @@ -1508,7 +1508,7 @@ PHP_FUNCTION(unlink) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_PATH(filename, filename_len) Z_PARAM_OPTIONAL - Z_PARAM_RESOURCE(zcontext) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); context = php_stream_context_from_zval(zcontext, 0); @@ -1665,7 +1665,7 @@ PHP_FUNCTION(copy) Z_PARAM_PATH(source, source_len) Z_PARAM_PATH(target, target_len) Z_PARAM_OPTIONAL - Z_PARAM_RESOURCE(zcontext) + Z_PARAM_RESOURCE_EX(zcontext, 1, 0) ZEND_PARSE_PARAMETERS_END(); if (php_check_open_basedir(source)) { diff --git a/ext/standard/tests/file/bug74719.phpt b/ext/standard/tests/file/bug74719.phpt new file mode 100644 index 0000000000..57309bcf06 --- /dev/null +++ b/ext/standard/tests/file/bug74719.phpt @@ -0,0 +1,43 @@ +--TEST-- +Bug #74719 Allow NULL as context, testing fopen, rename, unlink, mkdir and rmdir +--CREDITS-- +Alexander Holman +--FILE-- + +===DONE=== +--EXPECT-- +ok +ok +ok +ok +ok +===DONE=== diff --git a/ext/standard/tests/file/fopen_variation4.phpt b/ext/standard/tests/file/fopen_variation4.phpt index 38f5fefe62..4bd5b2a446 100644 --- a/ext/standard/tests/file/fopen_variation4.phpt +++ b/ext/standard/tests/file/fopen_variation4.phpt @@ -182,12 +182,10 @@ Error: 2 - fopen() expects parameter 4 to be resource, array given, %s(%d) bool(false) --uppercase NULL-- -Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d) -bool(false) +ok --lowercase null-- -Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d) -bool(false) +ok --lowercase true-- Error: 2 - fopen() expects parameter 4 to be resource, boolean given, %s(%d) @@ -238,12 +236,10 @@ Error: 2 - fopen() expects parameter 4 to be resource, object given, %s(%d) bool(false) --undefined var-- -Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d) -bool(false) +ok --unset var-- -Error: 2 - fopen() expects parameter 4 to be resource, null given, %s(%d) -bool(false) +ok --file resource-- Error: 2 - fopen(): supplied resource is not a valid Stream-Context resource, %s(%d) diff --git a/ext/standard/tests/file/mkdir_variation4.phpt b/ext/standard/tests/file/mkdir_variation4.phpt index deb6ff4a45..a866f8d16f 100644 --- a/ext/standard/tests/file/mkdir_variation4.phpt +++ b/ext/standard/tests/file/mkdir_variation4.phpt @@ -167,10 +167,10 @@ Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) Error: 2 - mkdir() expects parameter 4 to be resource, array given, %s(%d) --uppercase NULL-- -Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) +Directory created --lowercase null-- -Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) +Directory created --lowercase true-- Error: 2 - mkdir() expects parameter 4 to be resource, boolean given, %s(%d) @@ -209,10 +209,10 @@ Error: 2 - mkdir() expects parameter 4 to be resource, object given, %s(%d) Error: 2 - mkdir() expects parameter 4 to be resource, object given, %s(%d) --undefined var-- -Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) +Directory created --unset var-- -Error: 2 - mkdir() expects parameter 4 to be resource, null given, %s(%d) +Directory created --file resource-- Error: 2 - mkdir(): supplied resource is not a valid Stream-Context resource, %s(%d) diff --git a/ext/standard/tests/file/rename_variation10.phpt b/ext/standard/tests/file/rename_variation10.phpt index 42909ee484..5c81757ed8 100644 --- a/ext/standard/tests/file/rename_variation10.phpt +++ b/ext/standard/tests/file/rename_variation10.phpt @@ -184,12 +184,10 @@ Error: 2 - rename() expects parameter 3 to be resource, array given, %s(%d) bool(false) --uppercase NULL-- -Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d) -bool(false) +bool(true) --lowercase null-- -Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d) -bool(false) +bool(true) --lowercase true-- Error: 2 - rename() expects parameter 3 to be resource, boolean given, %s(%d) @@ -240,12 +238,10 @@ Error: 2 - rename() expects parameter 3 to be resource, object given, %s(%d) bool(false) --undefined var-- -Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d) -bool(false) +bool(true) --unset var-- -Error: 2 - rename() expects parameter 3 to be resource, null given, %s(%d) -bool(false) +bool(true) --file resource-- Error: 2 - rename(): supplied resource is not a valid Stream-Context resource, %s(%d) diff --git a/ext/standard/tests/file/rmdir_variation2.phpt b/ext/standard/tests/file/rmdir_variation2.phpt index 7b4311c245..6053018f42 100644 --- a/ext/standard/tests/file/rmdir_variation2.phpt +++ b/ext/standard/tests/file/rmdir_variation2.phpt @@ -175,12 +175,10 @@ Error: 2 - rmdir() expects parameter 2 to be resource, array given, %s(%d) bool(false) --uppercase NULL-- -Error: 2 - rmdir() expects parameter 2 to be resource, null given, %s(%d) -bool(false) +bool(true) --lowercase null-- -Error: 2 - rmdir() expects parameter 2 to be resource, null given, %s(%d) -bool(false) +bool(true) --lowercase true-- Error: 2 - rmdir() expects parameter 2 to be resource, boolean given, %s(%d) @@ -231,12 +229,10 @@ Error: 2 - rmdir() expects parameter 2 to be resource, object given, %s(%d) bool(false) --undefined var-- -Error: 2 - rmdir() expects parameter 2 to be resource, null given, %s(%d) -bool(false) +bool(true) --unset var-- -Error: 2 - rmdir() expects parameter 2 to be resource, null given, %s(%d) -bool(false) +bool(true) --0-- Error: 2 - rmdir(): supplied resource is not a valid Stream-Context resource, %s(%d) diff --git a/ext/standard/tests/file/unlink_error-win32-mb.phpt b/ext/standard/tests/file/unlink_error-win32-mb.phpt index 4ce4ca796a..51afc369b7 100644 --- a/ext/standard/tests/file/unlink_error-win32-mb.phpt +++ b/ext/standard/tests/file/unlink_error-win32-mb.phpt @@ -45,7 +45,6 @@ var_dump( file_exists(false) ); // confirm file doesnt exist var_dump( unlink($filename, '') ); // $context as empty string var_dump( unlink($filename, false) ); // $context as boolean false -var_dump( unlink($filename, NULL) ); // $context as NULL echo "\n-- Testing unlink() on non-existent file --\n"; @@ -98,9 +97,6 @@ bool(false) Warning: unlink() expects parameter 2 to be resource, boolean given in %s on line %d bool(false) -Warning: unlink() expects parameter 2 to be resource, null given in %s on line %d -bool(false) - -- Testing unlink() on non-existent file -- Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d diff --git a/ext/standard/tests/file/unlink_error-win32.phpt b/ext/standard/tests/file/unlink_error-win32.phpt index f7a123919f..305e989962 100644 --- a/ext/standard/tests/file/unlink_error-win32.phpt +++ b/ext/standard/tests/file/unlink_error-win32.phpt @@ -43,7 +43,6 @@ var_dump( file_exists(false) ); // confirm file doesnt exist var_dump( unlink($filename, '') ); // $context as empty string var_dump( unlink($filename, false) ); // $context as boolean false -var_dump( unlink($filename, NULL) ); // $context as NULL echo "\n-- Testing unlink() on non-existent file --\n"; @@ -95,9 +94,6 @@ bool(false) Warning: unlink() expects parameter 2 to be resource, boolean given in %s on line %d bool(false) -Warning: unlink() expects parameter 2 to be resource, null given in %s on line %d -bool(false) - -- Testing unlink() on non-existent file -- Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d diff --git a/ext/standard/tests/file/unlink_error.phpt b/ext/standard/tests/file/unlink_error.phpt index ae888bce4a..b1af8fd736 100644 --- a/ext/standard/tests/file/unlink_error.phpt +++ b/ext/standard/tests/file/unlink_error.phpt @@ -43,7 +43,6 @@ var_dump( file_exists(false) ); // confirm file doesnt exist var_dump( unlink($filename, '') ); // $context as empty string var_dump( unlink($filename, false) ); // $context as boolean false -var_dump( unlink($filename, NULL) ); // $context as NULL echo "\n-- Testing unlink() on non-existent file --\n"; @@ -95,9 +94,6 @@ bool(false) Warning: unlink() expects parameter 2 to be resource, boolean given in %s on line %d bool(false) -Warning: unlink() expects parameter 2 to be resource, null given in %s on line %d -bool(false) - -- Testing unlink() on non-existent file -- Warning: unlink(%s/non_existent_file.tmp): No such file or directory in %s on line %d diff --git a/ext/standard/tests/file/unlink_variation7.phpt b/ext/standard/tests/file/unlink_variation7.phpt index 64a2607d5f..f165e4e9c2 100644 --- a/ext/standard/tests/file/unlink_variation7.phpt +++ b/ext/standard/tests/file/unlink_variation7.phpt @@ -177,12 +177,10 @@ Error: 2 - unlink() expects parameter 2 to be resource, array given, %s(%d) bool(false) --uppercase NULL-- -Error: 2 - unlink() expects parameter 2 to be resource, null given, %s(%d) -bool(false) +bool(true) --lowercase null-- -Error: 2 - unlink() expects parameter 2 to be resource, null given, %s(%d) -bool(false) +bool(true) --lowercase true-- Error: 2 - unlink() expects parameter 2 to be resource, boolean given, %s(%d) @@ -233,12 +231,10 @@ Error: 2 - unlink() expects parameter 2 to be resource, object given, %s(%d) bool(false) --undefined var-- -Error: 2 - unlink() expects parameter 2 to be resource, null given, %s(%d) -bool(false) +bool(true) --unset var-- -Error: 2 - unlink() expects parameter 2 to be resource, null given, %s(%d) -bool(false) +bool(true) --file resource-- Error: 2 - unlink(): supplied resource is not a valid Stream-Context resource, %s(%d)