Skip to content

Commit ce9f1a4

Browse files
committed
Fixed bug #51860 (Include fails with toplevel symlink to /)
1 parent c5bb171 commit ce9f1a4

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PHP NEWS
1212
(Dmitry, Laruence)
1313
. Fix bug #60895 (Possible invalid handler usage in windows random
1414
functions). (Pierre)
15+
. Fixed bug #51860 (Include fails with toplevel symlink to /). (Dmitry)
1516

1617
- Firebird Database extension (ibase):
1718
. Fixed bug #60802 (ibase_trans() gives segfault when passing params).

TSRM/tsrm_virtual_cwd.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,9 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
773773

774774
while (1) {
775775
if (len <= start) {
776+
if (link_is_dir) {
777+
*link_is_dir = 1;
778+
}
776779
return start;
777780
}
778781

@@ -789,6 +792,10 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
789792
continue;
790793
} else if (i == len - 2 && path[i] == '.' && path[i+1] == '.') {
791794
/* remove '..' and previous directory */
795+
is_dir = 1;
796+
if (link_is_dir) {
797+
*link_is_dir = 1;
798+
}
792799
if (i - 1 <= start) {
793800
return start ? start : len;
794801
}
@@ -1214,9 +1221,14 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
12141221
return 1;
12151222
}
12161223
memcpy(resolved_path, state->cwd, state_cwd_length);
1217-
resolved_path[state_cwd_length] = DEFAULT_SLASH;
1218-
memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1);
1219-
path_length += state_cwd_length + 1;
1224+
if (resolved_path[state_cwd_length-1] == DEFAULT_SLASH) {
1225+
memcpy(resolved_path + state_cwd_length, path, path_length + 1);
1226+
path_length += state_cwd_length;
1227+
} else {
1228+
resolved_path[state_cwd_length] = DEFAULT_SLASH;
1229+
memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1);
1230+
path_length += state_cwd_length + 1;
1231+
}
12201232
}
12211233
} else {
12221234
#ifdef TSRM_WIN32

0 commit comments

Comments
 (0)