diff --git a/NEWS b/NEWS index 19ec0c4c60c..27b88eb0d16 100644 --- a/NEWS +++ b/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) diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c index 71f97814426..234f5a1b6bb 100644 --- a/Zend/zend_virtual_cwd.c +++ b/Zend/zend_virtual_cwd.c @@ -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 diff --git a/ext/phar/tests/phar_buildfromdirectory2-win.phpt b/ext/phar/tests/phar_buildfromdirectory2-win.phpt index 99d1ee7a060..ca22d394fa1 100644 --- a/ext/phar/tests/phar_buildfromdirectory2-win.phpt +++ b/ext/phar/tests/phar_buildfromdirectory2-win.phpt @@ -25,4 +25,4 @@ __HALT_COMPILER(); ?> --EXPECTF-- %s(24) "UnexpectedValueException" -RecursiveDirectoryIterator::__construct(1,1): %s (code: 2) +RecursiveDirectoryIterator::__construct(1): %s (code: 2) diff --git a/ext/phar/tests/phar_gobyebye-win32.phpt b/ext/phar/tests/phar_gobyebye-win32.phpt index f4120902b3b..d9487ac2db3 100644 --- a/ext/phar/tests/phar_gobyebye-win32.phpt +++ b/ext/phar/tests/phar_gobyebye-win32.phpt @@ -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 diff --git a/ext/standard/tests/dir/bug80960.phpt b/ext/standard/tests/dir/bug80960.phpt new file mode 100644 index 00000000000..703678de074 --- /dev/null +++ b/ext/standard/tests/dir/bug80960.phpt @@ -0,0 +1,26 @@ +--TEST-- +Fix #80960 (opendir() warning wrong info when failed on Windows) +--SKIPIF-- + +--INI-- +log_errors_max_len=0 +--FILE-- + +--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 diff --git a/ext/standard/tests/dir/opendir_variation6-win32.phpt b/ext/standard/tests/dir/opendir_variation6-win32.phpt index e2f42359d1d..40a0e919782 100644 --- a/ext/standard/tests/dir/opendir_variation6-win32.phpt +++ b/ext/standard/tests/dir/opendir_variation6-win32.phpt @@ -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) diff --git a/ext/standard/tests/general_functions/bug44295-win.phpt b/ext/standard/tests/general_functions/bug44295-win.phpt index 13a8918bcd3..e5eb4c26a94 100644 --- a/ext/standard/tests/general_functions/bug44295-win.phpt +++ b/ext/standard/tests/general_functions/bug44295-win.phpt @@ -25,5 +25,5 @@ try { --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== diff --git a/main/main.c b/main/main.c index d2d19a5ee82..d59207f45cc 100644 --- a/main/main.c +++ b/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); diff --git a/main/php.h b/main/php.h index f796577249d..cc8ac0e79c2 100644 --- a/main/php.h +++ b/main/php.h @@ -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() diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c index e3eda978d87..fe33fccff61 100644 --- a/main/streams/plain_wrapper.c +++ b/main/streams/plain_wrapper.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) {