Skip to content

Fix #79806: realpath() erroneously resolves link to link #5861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Zend/zend_virtual_cwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -928,7 +929,7 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
dataw.dwFileAttributes = fileInformation.dwFileAttributes;
CloseHandle(hLink);
(*ll)--;
goto retry;
goto retry_reparse_tag_cloud;
}
free_alloca(tmp, use_heap);
CloseHandle(hLink);
Expand Down Expand Up @@ -1075,6 +1076,22 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
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*/
Expand Down
6 changes: 0 additions & 6 deletions ext/standard/tests/file/realpath_basic4.phpt
Original file line number Diff line number Diff line change
@@ -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__);
Expand Down