com php-src: Fix #79806: realpath() erroneously resolves link to link: NEWS Zend/zend_virtual_cwd.c ext/standard/tests/file/realpat h_basic4.phpt
| From: | Christoph Michael Becker | Date: | Tue, 28 Jul 2020 11:55:22 +0000 |
| Subject: | com php-src: Fix #79806: realpath() erroneously resolves link to link: NEWS Zend/zend_virtual_cwd.c ext/standard/tests/file/realpat h_basic4.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-112406@lists.php.net to get a copy of this message | ||
Commit: c756f82c02a004fb45fed098468644b843a908c2
Author: Christoph M. Becker <cmbecker69@gmx.de> Tue, 28 Jul 2020 11:22:57 +0200
Parents: efe6d96b450202d17b728a20f9f3b2def3288ec0
Branches: PHP-7.3 PHP-7..4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c756f82c02a004fb45fed098468644b843a908c2
Log:
Fix #79806: realpath() erroneously resolves link to link
After resolving reparse points, the path still may be a reparse point;
in that case we have to resolve that reparse point as well.
Bugs:
https://bugs.php.net/79806
Changed paths:
M NEWS
M Zend/zend_virtual_cwd.c
M ext/standard/tests/file/realpath_basic4.phpt
Diff:
diff --git a/NEWS b/NEWS
index cc882ef1e2..8764bcb1c2 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ PHP NEWS
- Core:
. Fixed bug #79884 (PHP_CONFIG_FILE_PATH is meaningless). (cmb)
. Fixed bug #77932 (File extensions are case-sensitive). (cmb)
+ . Fixed bug #79806 (realpath() erroneously resolves link to link). (cmb)
- LDAP:
. Fixed memory leaks. (ptomulik)
diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c
index 253ed8c420...7c5ac825c5 100644
--- a/Zend/zend_virtual_cwd.c
+++ b/Zend/zend_virtual_cwd.c
@@ -845,6 +845,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
}
#ifdef ZEND_WIN32
+retry_reparse_point:
if (save) {
pathw = php_win32_ioutil_any_to_w(path);
if (!pathw) {
@@ -867,7 +868,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
tmp = do_alloca(len+1, use_heap);
memcpy(tmp, path, len+1);
-retry:
+retry_reparse_tag_cloud:
if(save &&
!(IS_UNC_PATH(path, len) && len >= 3 && path[2] != '?') &&
(dataw.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
@@ -928,7 +929,7 @@ retry:
dataw.dwFileAttributes = fileInformation.dwFileAttributes;
CloseHandle(hLink);
(*ll)--;
- goto retry;
+ goto retry_reparse_tag_cloud;
}
free_alloca(tmp, use_heap);
CloseHandle(hLink);
@@ -1075,6 +1076,22 @@ retry:
free_alloca(pbuffer, use_heap_large);
free(substitutename);
+ {
+ DWORD attrs;
+
+ FREE_PATHW()
+ pathw = php_win32_ioutil_any_to_w(path);
+ if (!pathw) {
+ return (size_t)-1;
+ }
+ attrs = GetFileAttributesW(pathw);
+ if (!isVolume && attrs != INVALID_FILE_ATTRIBUTES && (attrs &
FILE_ATTRIBUTE_REPARSE_POINT)) {
+ free_alloca(tmp, use_heap);
+ FREE_PATHW()
+ goto retry_reparse_point;
+ }
+ }
+
if(isabsolute == 1) {
if (!((j == 3) && (path[1] == ':') && (path[2] == '\\'))) {
/* use_realpath is 0 in the call below coz path is absolute*/
diff --git a/ext/standard/tests/file/realpath_basic4.phpt
b/ext/standard/tests/file/realpath_basic4.phpt
index d782b6d618..5f18dd9841 100644
--- a/ext/standard/tests/file/realpath_basic4.phpt
+++ b/ext/standard/tests/file/realpath_basic4.phpt
@@ -1,11 +1,5 @@
--TEST--
Test realpath() with relative paths
---SKIPIF--
-<?php
-if (substr(PHP_OS, 0, 3) == 'WIN') {
- die('skip no symlinks on Windows');
-}
-?>
--FILE--
<?php
$file_path = dirname(__FILE__);