Skip to content

Fix for Bug #74719 #3006

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

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion ext/curl/tests/check_win_config.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ GSSAPI => No
KERBEROS5 => Yes
UNIX_SOCKETS => No
PSL => No
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smtp, smtps, telnet, tftp
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, pop3, pop3s, rtsp, scp, sftp, smb, smbs, smtp, smtps, telnet, tftp
Host => %s-pc-win32
SSL Version => OpenSSL/%s
ZLib Version => %s
Expand Down
12 changes: 6 additions & 6 deletions ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,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);
Expand Down Expand Up @@ -1344,7 +1344,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);
Expand All @@ -1365,7 +1365,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);
Expand Down Expand Up @@ -1467,7 +1467,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);
Expand Down Expand Up @@ -1506,7 +1506,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);
Expand Down Expand Up @@ -1663,7 +1663,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)) {
Expand Down
61 changes: 61 additions & 0 deletions ext/standard/tests/file/bug74719.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
--TEST--
Bug #74719 Allow NULL as context, testing fopen, rename, unlink, mkdir and rmdir
--CREDITS--
Alexander Holman <alexander@holman.org.uk>
--FILE--
<?php
/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
* Description: Open a file or a URL and return a file pointer
* Source code: ext/standard/file.c
* Alias to functions:
*/

require_once('fopen_include_path.inc');

$thisTestDir = basename(__FILE__, ".php") . ".dir";
mkdir($thisTestDir);
chdir($thisTestDir);

$newpath = relative_include_path();
set_include_path($newpath);

// fopen
$tmpfile = basename(__FILE__, ".php") . ".tmp";
$h = fopen($tmpfile, "w", true, NULL);
if ($h !== false) {
echo "ok\n";
fclose($h);
}
$newTmpFile = "renamed_" . $tmpfile;

if (rename($tmpfile, $newTmpFile, NULL)) {
echo "ok\n";
}

if (unlink($newTmpFile, NULL)) {
echo "ok\n";
}

$tmpDir = "tmpDir";

if (mkdir($tmpDir, 0777, false, NULL)) {
echo "ok\n";
}

if (rmdir($tmpDir, NULL)) {
echo "ok\n";
}

teardown_relative_path();
restore_include_path();
chdir("..");
rmdir($thisTestDir);
?>
===DONE===
--EXPECT--
ok
ok
ok
ok
ok
===DONE===
12 changes: 4 additions & 8 deletions ext/standard/tests/file/fopen_variation4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions ext/standard/tests/file/mkdir_variation4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions ext/standard/tests/file/rename_variation10.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 4 additions & 8 deletions ext/standard/tests/file/rmdir_variation2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions ext/standard/tests/file/unlink_error-win32-mb.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions ext/standard/tests/file/unlink_error-win32.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions ext/standard/tests/file/unlink_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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
Expand Down
12 changes: 4 additions & 8 deletions ext/standard/tests/file/unlink_variation7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down