mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #80960: opendir() warning wrong info when failed on Windows
This commit is contained in:
4
NEWS
4
NEWS
@@ -2,6 +2,10 @@ PHP NEWS
|
||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
?? ??? 2021, PHP 8.0.6
|
||||
|
||||
- Core:
|
||||
. Fixed bug #80960 (opendir() warning wrong info when failed on Windows).
|
||||
(cmb)
|
||||
|
||||
- SPL:
|
||||
. Fixed bug #80933 (SplFileObject::DROP_NEW_LINE is broken for NUL and CR).
|
||||
(cmb, Nikita)
|
||||
|
||||
@@ -1061,6 +1061,11 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
}
|
||||
#endif
|
||||
if (path_length + state_cwd_length + 1 >= MAXPATHLEN-1) {
|
||||
#ifdef ZEND_WIN32
|
||||
SET_ERRNO_FROM_WIN32_CODE(ERROR_BUFFER_OVERFLOW);
|
||||
#else
|
||||
errno = ENAMETOOLONG;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
memcpy(resolved_path, state->cwd, state_cwd_length);
|
||||
@@ -1089,6 +1094,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
|
||||
#ifdef ZEND_WIN32
|
||||
if (memchr(resolved_path, '*', path_length) ||
|
||||
memchr(resolved_path, '?', path_length)) {
|
||||
SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_NAME);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,4 +25,4 @@ __HALT_COMPILER();
|
||||
?>
|
||||
--EXPECTF--
|
||||
%s(24) "UnexpectedValueException"
|
||||
RecursiveDirectoryIterator::__construct(1,1): %s (code: 2)
|
||||
RecursiveDirectoryIterator::__construct(1): %s (code: 2)
|
||||
|
||||
@@ -41,6 +41,6 @@ bool(false)
|
||||
bool(false)
|
||||
bool(false)
|
||||
|
||||
Warning: opendir(foo/hi,foo/hi): %s (code: 3) in phar://%sphar_gobyebye-win32.phar.php/foo/hi on line %d
|
||||
Warning: opendir(foo/hi): %s (code: 3) in phar://%sphar_gobyebye-win32.phar.php/foo/hi on line %d
|
||||
|
||||
Warning: opendir(foo/hi): Failed to open directory: No such file or directory in phar://%sphar_gobyebye-win32.phar.php/foo/hi on line %d
|
||||
|
||||
26
ext/standard/tests/dir/bug80960.phpt
Normal file
26
ext/standard/tests/dir/bug80960.phpt
Normal file
@@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
Fix #80960 (opendir() warning wrong info when failed on Windows)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (PHP_OS_FAMILY !== "Windows") die("skip for Windows only");
|
||||
?>
|
||||
--INI--
|
||||
log_errors_max_len=0
|
||||
--FILE--
|
||||
<?php
|
||||
opendir("notexist*");
|
||||
opendir("notexist?");
|
||||
opendir(str_pad("longname", PHP_MAXPATHLEN - strlen(getcwd()), "_"));
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: opendir(notexist*): %s (code: 123) in %s on line %d
|
||||
|
||||
Warning: opendir(notexist*): failed to open dir: No such file or directory in %s on line %d
|
||||
|
||||
Warning: opendir(notexist?): %s (code: 123) in %s on line %d
|
||||
|
||||
Warning: opendir(notexist?): failed to open dir: No such file or directory in %s on line %d
|
||||
|
||||
Warning: opendir(longname%r_+%r): %s (code: 111) in %s on line %d
|
||||
|
||||
Warning: opendir(longname%r_+%r): failed to open dir: Filename too long in %s on line %d
|
||||
@@ -45,24 +45,24 @@ rmdir($dir_path);
|
||||
|
||||
-- Wildcard = '*' --
|
||||
|
||||
Warning: opendir(%s/opendir_var*,%s/opendir_var*): %s in %s on line %d
|
||||
Warning: opendir(%s/opendir_var*): %s in %s on line %d
|
||||
|
||||
Warning: opendir(%s/opendir_var*): Failed to open directory: %s in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: opendir(%s/*,%s/*): %s in %s on line %d
|
||||
Warning: opendir(%s/*): %s in %s on line %d
|
||||
|
||||
Warning: opendir(%s/*): Failed to open directory: %s in %s on line %d
|
||||
bool(false)
|
||||
|
||||
-- Wildcard = '?' --
|
||||
|
||||
Warning: opendir(%s/opendir_variation6/sub_dir?,%s/opendir_variation6/sub_dir?): %s in %s on line %d
|
||||
Warning: opendir(%s/opendir_variation6/sub_dir?): %s in %s on line %d
|
||||
|
||||
Warning: opendir(%s/opendir_variation6/sub_dir?): Failed to open directory: %s in %s on line %d
|
||||
bool(false)
|
||||
|
||||
Warning: opendir(%s/opendir_variation6/sub?dir1,%s/opendir_variation6/sub?dir1): %s in %s on line %d
|
||||
Warning: opendir(%s/opendir_variation6/sub?dir1): %s in %s on line %d
|
||||
|
||||
Warning: opendir(%s/opendir_variation6/sub?dir1): Failed to open directory: %s in %s on line %d
|
||||
bool(false)
|
||||
|
||||
@@ -25,5 +25,5 @@ try {
|
||||
<?php exit(0); ?>
|
||||
--EXPECTF--
|
||||
before
|
||||
in catch: DirectoryIterator::__construct(c:\not\exists\here,c:\not\exists\here): %s (code: 3)
|
||||
in catch: DirectoryIterator::__construct(c:\not\exists\here): %s (code: 3)
|
||||
==DONE==
|
||||
|
||||
13
main/main.c
13
main/main.c
@@ -1108,6 +1108,19 @@ PHPAPI ZEND_COLD void php_error_docref2(const char *docref, const char *param1,
|
||||
/* }}} */
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
PHPAPI ZEND_COLD void php_win32_docref1_from_error(DWORD error, const char *param1) {
|
||||
char *buf = php_win32_error_to_msg(error);
|
||||
size_t buf_len;
|
||||
|
||||
buf_len = strlen(buf);
|
||||
if (buf_len >= 2) {
|
||||
buf[buf_len - 1] = '\0';
|
||||
buf[buf_len - 2] = '\0';
|
||||
}
|
||||
php_error_docref1(NULL, param1, E_WARNING, "%s (code: %lu)", buf, error);
|
||||
php_win32_error_msg_free(buf);
|
||||
}
|
||||
|
||||
PHPAPI ZEND_COLD void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2) {
|
||||
char *buf = php_win32_error_to_msg(error);
|
||||
php_error_docref2(NULL, param1, param2, E_WARNING, "%s (code: %lu)", buf, error);
|
||||
|
||||
@@ -345,6 +345,7 @@ PHPAPI ZEND_COLD void php_error_docref1(const char *docref, const char *param1,
|
||||
PHPAPI ZEND_COLD void php_error_docref2(const char *docref, const char *param1, const char *param2, int type, const char *format, ...)
|
||||
PHP_ATTRIBUTE_FORMAT(printf, 5, 6);
|
||||
#ifdef PHP_WIN32
|
||||
PHPAPI ZEND_COLD void php_win32_docref1_from_error(DWORD error, const char *param1);
|
||||
PHPAPI ZEND_COLD void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2);
|
||||
#endif
|
||||
END_EXTERN_C()
|
||||
|
||||
@@ -1026,7 +1026,7 @@ static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const
|
||||
|
||||
#ifdef PHP_WIN32
|
||||
if (!dir) {
|
||||
php_win32_docref2_from_error(GetLastError(), path, path);
|
||||
php_win32_docref1_from_error(GetLastError(), path);
|
||||
}
|
||||
|
||||
if (dir && dir->finished) {
|
||||
|
||||
Reference in New Issue
Block a user