Skip to content

Commit cb262cd

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #80960: opendir() warning wrong info when failed on Windows
2 parents d4a206b + ea3c992 commit cb262cd

File tree

10 files changed

+58
-8
lines changed

10 files changed

+58
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2021, PHP 8.0.6
44

5+
- Core:
6+
. Fixed bug #80960 (opendir() warning wrong info when failed on Windows).
7+
(cmb)
8+
59
- SPL:
610
. Fixed bug #80933 (SplFileObject::DROP_NEW_LINE is broken for NUL and CR).
711
(cmb, Nikita)

Zend/zend_virtual_cwd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,11 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
10611061
}
10621062
#endif
10631063
if (path_length + state_cwd_length + 1 >= MAXPATHLEN-1) {
1064+
#ifdef ZEND_WIN32
1065+
SET_ERRNO_FROM_WIN32_CODE(ERROR_BUFFER_OVERFLOW);
1066+
#else
1067+
errno = ENAMETOOLONG;
1068+
#endif
10641069
return 1;
10651070
}
10661071
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
10891094
#ifdef ZEND_WIN32
10901095
if (memchr(resolved_path, '*', path_length) ||
10911096
memchr(resolved_path, '?', path_length)) {
1097+
SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_NAME);
10921098
return 1;
10931099
}
10941100
#endif

ext/phar/tests/phar_buildfromdirectory2-win.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ __HALT_COMPILER();
2525
?>
2626
--EXPECTF--
2727
%s(24) "UnexpectedValueException"
28-
RecursiveDirectoryIterator::__construct(1,1): %s (code: 2)
28+
RecursiveDirectoryIterator::__construct(1): %s (code: 2)

ext/phar/tests/phar_gobyebye-win32.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ bool(false)
4141
bool(false)
4242
bool(false)
4343

44-
Warning: opendir(foo/hi,foo/hi): %s (code: 3) in phar://%sphar_gobyebye-win32.phar.php/foo/hi on line %d
44+
Warning: opendir(foo/hi): %s (code: 3) in phar://%sphar_gobyebye-win32.phar.php/foo/hi on line %d
4545

4646
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

ext/standard/tests/dir/bug80960.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Fix #80960 (opendir() warning wrong info when failed on Windows)
3+
--SKIPIF--
4+
<?php
5+
if (PHP_OS_FAMILY !== "Windows") die("skip for Windows only");
6+
?>
7+
--INI--
8+
log_errors_max_len=0
9+
--FILE--
10+
<?php
11+
opendir("notexist*");
12+
opendir("notexist?");
13+
opendir(str_pad("longname", PHP_MAXPATHLEN - strlen(getcwd()), "_"));
14+
?>
15+
--EXPECTF--
16+
Warning: opendir(notexist*): %s (code: 123) in %s on line %d
17+
18+
Warning: opendir(notexist*): failed to open dir: No such file or directory in %s on line %d
19+
20+
Warning: opendir(notexist?): %s (code: 123) in %s on line %d
21+
22+
Warning: opendir(notexist?): failed to open dir: No such file or directory in %s on line %d
23+
24+
Warning: opendir(longname%r_+%r): %s (code: 111) in %s on line %d
25+
26+
Warning: opendir(longname%r_+%r): failed to open dir: Filename too long in %s on line %d

ext/standard/tests/dir/opendir_variation6-win32.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ rmdir($dir_path);
4545

4646
-- Wildcard = '*' --
4747

48-
Warning: opendir(%s/opendir_var*,%s/opendir_var*): %s in %s on line %d
48+
Warning: opendir(%s/opendir_var*): %s in %s on line %d
4949

5050
Warning: opendir(%s/opendir_var*): Failed to open directory: %s in %s on line %d
5151
bool(false)
5252

53-
Warning: opendir(%s/*,%s/*): %s in %s on line %d
53+
Warning: opendir(%s/*): %s in %s on line %d
5454

5555
Warning: opendir(%s/*): Failed to open directory: %s in %s on line %d
5656
bool(false)
5757

5858
-- Wildcard = '?' --
5959

60-
Warning: opendir(%s/opendir_variation6/sub_dir?,%s/opendir_variation6/sub_dir?): %s in %s on line %d
60+
Warning: opendir(%s/opendir_variation6/sub_dir?): %s in %s on line %d
6161

6262
Warning: opendir(%s/opendir_variation6/sub_dir?): Failed to open directory: %s in %s on line %d
6363
bool(false)
6464

65-
Warning: opendir(%s/opendir_variation6/sub?dir1,%s/opendir_variation6/sub?dir1): %s in %s on line %d
65+
Warning: opendir(%s/opendir_variation6/sub?dir1): %s in %s on line %d
6666

6767
Warning: opendir(%s/opendir_variation6/sub?dir1): Failed to open directory: %s in %s on line %d
6868
bool(false)

ext/standard/tests/general_functions/bug44295-win.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ try {
2525
<?php exit(0); ?>
2626
--EXPECTF--
2727
before
28-
in catch: DirectoryIterator::__construct(c:\not\exists\here,c:\not\exists\here): %s (code: 3)
28+
in catch: DirectoryIterator::__construct(c:\not\exists\here): %s (code: 3)
2929
==DONE==

main/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,19 @@ PHPAPI ZEND_COLD void php_error_docref2(const char *docref, const char *param1,
11081108
/* }}} */
11091109

11101110
#ifdef PHP_WIN32
1111+
PHPAPI ZEND_COLD void php_win32_docref1_from_error(DWORD error, const char *param1) {
1112+
char *buf = php_win32_error_to_msg(error);
1113+
size_t buf_len;
1114+
1115+
buf_len = strlen(buf);
1116+
if (buf_len >= 2) {
1117+
buf[buf_len - 1] = '\0';
1118+
buf[buf_len - 2] = '\0';
1119+
}
1120+
php_error_docref1(NULL, param1, E_WARNING, "%s (code: %lu)", buf, error);
1121+
php_win32_error_msg_free(buf);
1122+
}
1123+
11111124
PHPAPI ZEND_COLD void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2) {
11121125
char *buf = php_win32_error_to_msg(error);
11131126
php_error_docref2(NULL, param1, param2, E_WARNING, "%s (code: %lu)", buf, error);

main/php.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ PHPAPI ZEND_COLD void php_error_docref1(const char *docref, const char *param1,
345345
PHPAPI ZEND_COLD void php_error_docref2(const char *docref, const char *param1, const char *param2, int type, const char *format, ...)
346346
PHP_ATTRIBUTE_FORMAT(printf, 5, 6);
347347
#ifdef PHP_WIN32
348+
PHPAPI ZEND_COLD void php_win32_docref1_from_error(DWORD error, const char *param1);
348349
PHPAPI ZEND_COLD void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2);
349350
#endif
350351
END_EXTERN_C()

main/streams/plain_wrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ static php_stream *php_plain_files_dir_opener(php_stream_wrapper *wrapper, const
10261026

10271027
#ifdef PHP_WIN32
10281028
if (!dir) {
1029-
php_win32_docref2_from_error(GetLastError(), path, path);
1029+
php_win32_docref1_from_error(GetLastError(), path);
10301030
}
10311031

10321032
if (dir && dir->finished) {

0 commit comments

Comments
 (0)