|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-04-16 07:08 UTC] 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
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 22:00:01 2025 UTC |
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