Bug #80960 [PATCH]: opendir() warning wrong info when failed on Windows
| From: | cmb@php.net | Date: | Fri, 16 Apr 2021 13:31:03 +0000 |
| Subject: | Bug #80960 [PATCH]: opendir() warning wrong info when failed on Windows | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233469@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80960&edit=1
ID: 80960
Patch added by: cmb@php.net
Reported by: dixyes at gmail dot com
Summary: opendir() warning wrong info when failed on Windows
Status: Verified
Type: Bug
Package: *Directory/Filesystem functions
Operating System: Windows
PHP Version: Irrelevant
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The following pull request has been associated:
Patch Name: Fix #80960: opendir() warning wrong info when failed on Windows
On GitHub: https://github.com/php/php-src/pull/6872
Patch: https://github.com/php/php-src/pull/6872.patch
Previous Comments:
------------------------------------------------------------------------
[2021-04-16 12:57:07] cmb@php.net
Oh, wow, that is pretty broken indeed. Thanks for reporting!
One full example:
<?php
opendir("notexist*");
?>
Warning: opendir(notexist*,notexist*): The operation completed successfully. (code: 0) in %s on
line %d
Warning: opendir(notexist*): failed to open dir: File exists in %s on line %dir
So two wrong error messages (neither did the operation complete
successfully, nor does the file exist), plus the confusing
duplicate filename in the first message.
And to clarify: this is not particularly related to ZTS, and for
too long filenames partially affects non Windows systems as well.
> rather than EPERM like fopen pathes ending with space, that's
> really confusing
I agree (besides that it's ENOENT), and only in some occassions,
for instance:
<?php
rename("foo ", "bar ");
?>
Warning: rename(foo ,bar ): The filename, directory name, or volume label syntax is incorrect.
(code: 123) in %s on line %d
------------------------------------------------------------------------
[2021-04-16 07:08:30] dixyes at gmail dot com
Description:
------------
opendir("some bad path*"); will make strange warning.
maybe other functions will have similar behavior.
because virtual_file_ex() donot do SetLastError() when failed in some routines, this cause some
error message become corrupt.
Test script:
---------------
<?php
$filename = __DIR__ . "/afile";
const MAXPATHLEN = 2048; // PHP_WIN32_IOUTIL_MAXPATHLEN on my system
$cwd = getcwd();
define("LEN", MAXPATHLEN - strlen($cwd));
function tellmefail(){
// these should always tell me ERROR_INVALID_NAME "The filename, directory name, or volume
label syntax is incorrect."
// or same as error when path ending with space: ERROR_ACCESS_DENIED "Access is
denied."
// because the path is illegal,
// at least, warnings should be always the same
opendir("notexist*"); // * varient
opendir("notexist?"); // ? varient
opendir(str_pad("longname", LEN, "_"));
}
@rmdir($filename);
@unlink($filename);
@unlink($filename);
// should failed here with ERROR_FILE_NOT_FOUND
tellmefail();
@touch($filename);
@fopen($filename, "x");
// should failed here with ERROR_ALREADY_EXISTS
tellmefail();
@opendir($filename);
// should failed here with ERROR_DIRECTORY
tellmefail();
@unlink($filename);
@mkdir($filename);
@fopen($filename, "x");
// should failed here with ERROR_ACCESS_DENIED
// (on windows you need FILE_FLAG_BACKUP_SEMANTICS to open a dir via CreateFileW, otherwise failed
with ERROR_ACCESS_DENIED)
tellmefail();
// clean up
@rmdir($filename);
@unlink($filename);
Expected result:
----------------
all the warnings should be the same,
if possible, use EINVAL/ERROR_INVALID_NAME/"The filename, directory name, or volume label
syntax is incorrect." as error text(rather than EPERM like fopen pathes ending with space,
that's really confusing).
Actual result:
--------------
all the warings become early error
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80960&edit=1