Skip to content

Commit 85a26fe

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79806: realpath() erroneously resolves link to link
2 parents 68aa132 + d5b59b4 commit 85a26fe

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- Core:
66
. Fixed bug #79884 (PHP_CONFIG_FILE_PATH is meaningless). (cmb)
77
. Fixed bug #77932 (File extensions are case-sensitive). (cmb)
8+
. Fixed bug #79806 (realpath() erroneously resolves link to link). (cmb)
89

910
06 Aug 2020, PHP 7.4.9
1011

Zend/zend_virtual_cwd.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
596596
}
597597

598598
#ifdef ZEND_WIN32
599+
retry_reparse_point:
599600
if (save) {
600601
pathw = php_win32_ioutil_any_to_w(path);
601602
if (!pathw) {
@@ -618,7 +619,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
618619
tmp = do_alloca(len+1, use_heap);
619620
memcpy(tmp, path, len+1);
620621

621-
retry:
622+
retry_reparse_tag_cloud:
622623
if(save &&
623624
!(IS_UNC_PATH(path, len) && len >= 3 && path[2] != '?') &&
624625
(dataw.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
@@ -679,7 +680,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
679680
dataw.dwFileAttributes = fileInformation.dwFileAttributes;
680681
CloseHandle(hLink);
681682
(*ll)--;
682-
goto retry;
683+
goto retry_reparse_tag_cloud;
683684
}
684685
free_alloca(tmp, use_heap);
685686
CloseHandle(hLink);
@@ -826,6 +827,15 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
826827
free_alloca(pbuffer, use_heap_large);
827828
free(substitutename);
828829

830+
{
831+
DWORD attrs = GetFileAttributesA(path);
832+
if (!isVolume && (attrs & FILE_ATTRIBUTE_REPARSE_POINT)) {
833+
free_alloca(tmp, use_heap);
834+
FREE_PATHW()
835+
goto retry_reparse_point;
836+
}
837+
}
838+
829839
if(isabsolute == 1) {
830840
if (!((j == 3) && (path[1] == ':') && (path[2] == '\\'))) {
831841
/* use_realpath is 0 in the call below coz path is absolute*/

ext/standard/tests/file/realpath_basic4.phpt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
--TEST--
22
Test realpath() with relative paths
3-
--SKIPIF--
4-
<?php
5-
if (substr(PHP_OS, 0, 3) == 'WIN') {
6-
die('skip not for Windows');
7-
}
8-
?>
93
--FILE--
104
<?php
115
$file_path = __DIR__;

0 commit comments

Comments
 (0)