Skip to content

Commit 54e15dc

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79806: realpath() erroneously resolves link to link
2 parents 6d97e7f + 85a26fe commit 54e15dc

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Zend/zend_virtual_cwd.c

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

592592
#ifdef ZEND_WIN32
593+
retry_reparse_point:
593594
if (save) {
594595
pathw = php_win32_ioutil_any_to_w(path);
595596
if (!pathw) {
@@ -612,7 +613,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
612613
tmp = do_alloca(len+1, use_heap);
613614
memcpy(tmp, path, len+1);
614615

615-
retry:
616+
retry_reparse_tag_cloud:
616617
if(save &&
617618
!(IS_UNC_PATH(path, len) && len >= 3 && path[2] != '?') &&
618619
(dataw.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
@@ -673,7 +674,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
673674
dataw.dwFileAttributes = fileInformation.dwFileAttributes;
674675
CloseHandle(hLink);
675676
(*ll)--;
676-
goto retry;
677+
goto retry_reparse_tag_cloud;
677678
}
678679
free_alloca(tmp, use_heap);
679680
CloseHandle(hLink);
@@ -820,6 +821,15 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
820821
free_alloca(pbuffer, use_heap_large);
821822
free(substitutename);
822823

824+
{
825+
DWORD attrs = GetFileAttributesA(path);
826+
if (!isVolume && (attrs & FILE_ATTRIBUTE_REPARSE_POINT)) {
827+
free_alloca(tmp, use_heap);
828+
FREE_PATHW()
829+
goto retry_reparse_point;
830+
}
831+
}
832+
823833
if(isabsolute == 1) {
824834
if (!((j == 3) && (path[1] == ':') && (path[2] == '\\'))) {
825835
/* 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)