Skip to content
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

fix file() flags error-check #11483

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/standard/file.c
Expand Up @@ -619,7 +619,8 @@ PHP_FUNCTION(file)
Z_PARAM_RESOURCE_OR_NULL(zcontext)
ZEND_PARSE_PARAMETERS_END();

if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) {
if ((flags & ~(PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES | PHP_FILE_NO_DEFAULT_CONTEXT)) != 0)
{
divinity76 marked this conversation as resolved.
Show resolved Hide resolved
zend_argument_value_error(2, "must be a valid flag value");
RETURN_THROWS();
}
Expand Down
16 changes: 12 additions & 4 deletions ext/standard/tests/file/file_error.phpt
Expand Up @@ -7,8 +7,16 @@ echo "\n*** Testing error conditions ***\n";
$file_handle = fopen($file_path."/file.tmp", "w");

$filename = $file_path."/file.tmp";
var_dump( file($filename, 10, NULL) ); // Incorrect flag

try {
var_dump( file($filename, 10, NULL) ); // Incorrect flag
} catch(ValueError $e) {
echo "ValueError: " . $e->getMessage() . "\n";
}
try {
var_dump( file($filename, FILE_APPEND) ); // Incorrect flag
} catch(ValueError $e) {
echo "ValueError: " . $e->getMessage() . "\n";
}
var_dump( file("temp.tmp") ); // non existing filename
fclose($file_handle);

Expand All @@ -21,8 +29,8 @@ unlink($file_path."/file.tmp");
?>
--EXPECTF--
*** Testing error conditions ***
array(0) {
}
ValueError: file(): Argument #2 ($flags) must be a valid flag value
ValueError: file(): Argument #2 ($flags) must be a valid flag value

Warning: file(temp.tmp): Failed to open stream: No such file or directory in %s on line %d
bool(false)
Expand Down
80 changes: 8 additions & 72 deletions ext/standard/tests/file/file_variation6.phpt
Expand Up @@ -95,78 +95,14 @@ array(3) {
[2]=>
string(6) "Line 3"
}
array(3) {
[0]=>
string(7) "Line 1
"
[1]=>
string(7) "Line 2
"
[2]=>
string(6) "Line 3"
}
array(3) {
[0]=>
string(7) "Line 1
"
[1]=>
string(7) "Line 2
"
[2]=>
string(6) "Line 3"
}
array(3) {
[0]=>
string(6) "Line 1"
[1]=>
string(6) "Line 2"
[2]=>
string(6) "Line 3"
}
array(3) {
[0]=>
string(6) "Line 1"
[1]=>
string(6) "Line 2"
[2]=>
string(6) "Line 3"
}
array(3) {
[0]=>
string(7) "Line 1
"
[1]=>
string(7) "Line 2
"
[2]=>
string(6) "Line 3"
}
array(3) {
[0]=>
string(7) "Line 1
"
[1]=>
string(7) "Line 2
"
[2]=>
string(6) "Line 3"
}
array(3) {
[0]=>
string(6) "Line 1"
[1]=>
string(6) "Line 2"
[2]=>
string(6) "Line 3"
}
array(3) {
[0]=>
string(6) "Line 1"
[1]=>
string(6) "Line 2"
[2]=>
string(6) "Line 3"
}
file(): Argument #2 ($flags) must be a valid flag value
file(): Argument #2 ($flags) must be a valid flag value
file(): Argument #2 ($flags) must be a valid flag value
file(): Argument #2 ($flags) must be a valid flag value
file(): Argument #2 ($flags) must be a valid flag value
file(): Argument #2 ($flags) must be a valid flag value
file(): Argument #2 ($flags) must be a valid flag value
file(): Argument #2 ($flags) must be a valid flag value
array(3) {
[0]=>
string(7) "Line 1
Expand Down