Bug #80960 [NEW]: opendir() warning wrong info when failed on Windows ZTS build

From: Date: Fri, 16 Apr 2021 07:08:30 +0000
Subject: Bug #80960 [NEW]: opendir() warning wrong info when failed on Windows ZTS build
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233455@lists.php.net to get a copy of this message
From:             dixyes at gmail dot com
Operating system: Windows
PHP version:      Irrelevant
Package:          *Directory/Filesystem functions
Bug Type:         Bug
Bug description:opendir() warning wrong info when failed on Windows ZTS build

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 bug report at https://bugs.php.net/bug.php?id=80960&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80960&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80960&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80960&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80960&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80960&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80960&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80960&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80960&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80960&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80960&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80960&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80960&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80960&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80960&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80960&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80960&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80960&r=mysqlcfg


Thread (4 messages)

« previous php.bugs (#233455) next »