Skip to content

Promote warnings to errors in dir stdlib extension #4643

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
wants to merge 2 commits into from
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
16 changes: 8 additions & 8 deletions ext/standard/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ PHP_FUNCTION(closedir)
FETCH_DIRP();

if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
RETURN_FALSE;
zend_type_error("%d is not a valid Directory resource", dirp->res->handle);
return;
}

res = dirp->res;
Expand Down Expand Up @@ -382,8 +382,8 @@ PHP_FUNCTION(rewinddir)
FETCH_DIRP();

if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
RETURN_FALSE;
zend_type_error("%d is not a valid Directory resource", dirp->res->handle);
return;
}

php_stream_rewinddir(dirp);
Expand All @@ -401,8 +401,8 @@ PHP_NAMED_FUNCTION(php_if_readdir)
FETCH_DIRP();

if (!(dirp->flags & PHP_STREAM_FLAG_IS_DIR)) {
php_error_docref(NULL, E_WARNING, "%d is not a valid Directory resource", dirp->res->handle);
RETURN_FALSE;
zend_type_error("%d is not a valid Directory resource", dirp->res->handle);
return;
}

if (php_stream_readdir(dirp, &entry)) {
Expand Down Expand Up @@ -566,8 +566,8 @@ PHP_FUNCTION(scandir)
ZEND_PARSE_PARAMETERS_END();

if (dirn_len < 1) {
php_error_docref(NULL, E_WARNING, "Directory name cannot be empty");
RETURN_FALSE;
zend_throw_error(NULL, "Directory name cannot be empty");
return;
}

if (zcontext) {
Expand Down
14 changes: 14 additions & 0 deletions ext/standard/tests/dir/bug41693.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Bug #41693 (scandir() allows empty directory names)
--FILE--
<?php

try {
var_dump(scandir(''));
} catch (\Error $e) {
echo $e->getMessage() . "\n";
}

?>
--EXPECT--
Directory name cannot be empty
11 changes: 6 additions & 5 deletions ext/standard/tests/dir/closedir_variation3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ echo "\n-- Open a file using fopen() --\n";
var_dump($fp = fopen(__FILE__, 'r'));

echo "\n-- Try to close the file pointer using closedir() --\n";
var_dump(closedir($fp));

try {
var_dump(closedir($fp));
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}
echo "\n-- Check file pointer: --\n";
var_dump($fp);

Expand All @@ -35,9 +38,7 @@ if(is_resource($fp)) {
resource(%d) of type (stream)

-- Try to close the file pointer using closedir() --

Warning: closedir(): %d is not a valid Directory resource in %s on line %d
bool(false)
%d is not a valid Directory resource

-- Check file pointer: --
resource(%d) of type (stream)
Expand Down
10 changes: 6 additions & 4 deletions ext/standard/tests/dir/readdir_variation7.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ echo "*** Testing readdir() : usage variations ***\n";

// get a resource variable
var_dump($fp = fopen(__FILE__, "r"));
var_dump( readdir($fp) );
try {
var_dump( readdir($fp) );
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}

?>
===DONE===
--EXPECTF--
*** Testing readdir() : usage variations ***
resource(%d) of type (stream)

Warning: readdir(): %d is not a valid Directory resource in %s on line %d
bool(false)
%d is not a valid Directory resource
===DONE===
11 changes: 7 additions & 4 deletions ext/standard/tests/dir/rewinddir_variation3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ echo "\n-- Open a file using fopen --\n";
var_dump($fp = fopen(__FILE__, 'r'));

$result1 = fread($fp, 5);
var_dump(rewinddir($fp));

try {
var_dump(rewinddir($fp));
} catch (\TypeError $e) {
echo $e->getMessage() . "\n";
}
$result2 = fread($fp, 5);

echo "\n-- Check if rewinddir() has repositioned the file pointer --\n";
Expand All @@ -34,9 +39,7 @@ if ($result1 === $result2) {

-- Open a file using fopen --
resource(%d) of type (stream)

Warning: rewinddir(): %d is not a valid Directory resource in %s on line %d
bool(false)
%d is not a valid Directory resource

-- Check if rewinddir() has repositioned the file pointer --
rewinddir() does not work on file pointers
Expand Down
13 changes: 0 additions & 13 deletions ext/standard/tests/file/bug41693.phpt

This file was deleted.