Skip to content

Commit 44ad2db

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79806: realpath() erroneously resolves link to link
2 parents f41bceb + e0ebe56 commit 44ad2db

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Zend/zend_virtual_cwd.c

Lines changed: 19 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,22 @@ 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;
826+
827+
FREE_PATHW()
828+
pathw = php_win32_ioutil_any_to_w(path);
829+
if (!pathw) {
830+
return (size_t)-1;
831+
}
832+
attrs = GetFileAttributesW(pathw);
833+
if (!isVolume && attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_REPARSE_POINT)) {
834+
free_alloca(tmp, use_heap);
835+
FREE_PATHW()
836+
goto retry_reparse_point;
837+
}
838+
}
839+
823840
if(isabsolute == 1) {
824841
if (!((j == 3) && (path[1] == ':') && (path[2] == '\\'))) {
825842
/* 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 no symlinks on Windows');
7-
}
8-
?>
93
--FILE--
104
<?php
115
$file_path = __DIR__;

0 commit comments

Comments
 (0)