Skip to content

Commit 0d32d36

Browse files
committed
Fixed bug #51860 (Include fails with toplevel symlink to /)
1 parent 2c1285a commit 0d32d36

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

TSRM/tsrm_virtual_cwd.c

+15-3
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,9 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
760760

761761
while (1) {
762762
if (len <= start) {
763+
if (link_is_dir) {
764+
*link_is_dir = 1;
765+
}
763766
return start;
764767
}
765768

@@ -776,6 +779,10 @@ static int tsrm_realpath_r(char *path, int start, int len, int *ll, time_t *t, i
776779
continue;
777780
} else if (i == len - 2 && path[i] == '.' && path[i+1] == '.') {
778781
/* remove '..' and previous directory */
782+
is_dir = 1;
783+
if (link_is_dir) {
784+
*link_is_dir = 1;
785+
}
779786
if (i - 1 <= start) {
780787
return start ? start : len;
781788
}
@@ -1200,9 +1207,14 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
12001207
return 1;
12011208
}
12021209
memcpy(resolved_path, state->cwd, state_cwd_length);
1203-
resolved_path[state_cwd_length] = DEFAULT_SLASH;
1204-
memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1);
1205-
path_length += state_cwd_length + 1;
1210+
if (resolved_path[state_cwd_length-1] == DEFAULT_SLASH) {
1211+
memcpy(resolved_path + state_cwd_length, path, path_length + 1);
1212+
path_length += state_cwd_length;
1213+
} else {
1214+
resolved_path[state_cwd_length] = DEFAULT_SLASH;
1215+
memcpy(resolved_path + state_cwd_length + 1, path, path_length + 1);
1216+
path_length += state_cwd_length + 1;
1217+
}
12061218
}
12071219
} else {
12081220
#ifdef TSRM_WIN32

0 commit comments

Comments
 (0)