Skip to content

Commit 199914b

Browse files
committed
Fixed bug #77317 __DIR__, __FILE__, realpath() reveal physical path for subst virtual drive
Keep compatibility with 7.2 and below which better comply with realpath(3). This might have been fixable another way, say by checking of QueryDosDevice or alike, sadly that comes with a huge performance impact. The new internal realpath API is kept available so is usable when bind or network mount or other OS specific realpath variants are needed. If not used by default, a userspace function for this specific case might be considered to be offered in next minor.
1 parent b45774e commit 199914b

File tree

1 file changed

+0
-54
lines changed

1 file changed

+0
-54
lines changed

Zend/zend_virtual_cwd.c

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,40 +1207,6 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
12071207
}
12081208
/* }}} */
12091209

1210-
#ifdef ZEND_WIN32
1211-
static size_t tsrm_win32_realpath_quick(char *path, size_t len, time_t *t) /* {{{ */
1212-
{
1213-
char tmp_resolved_path[MAXPATHLEN];
1214-
int tmp_resolved_path_len;
1215-
BY_HANDLE_FILE_INFORMATION info;
1216-
realpath_cache_bucket *bucket;
1217-
1218-
if (!*t) {
1219-
*t = time(0);
1220-
}
1221-
1222-
if (CWDG(realpath_cache_size_limit) && (bucket = realpath_cache_find(path, len, *t)) != NULL) {
1223-
memcpy(path, bucket->realpath, bucket->realpath_len + 1);
1224-
return bucket->realpath_len;
1225-
}
1226-
1227-
if (!php_win32_ioutil_realpath_ex0(path, tmp_resolved_path, &info)) {
1228-
DWORD err = GetLastError();
1229-
SET_ERRNO_FROM_WIN32_CODE(err);
1230-
return (size_t)-1;
1231-
}
1232-
1233-
tmp_resolved_path_len = strlen(tmp_resolved_path);
1234-
if (CWDG(realpath_cache_size_limit)) {
1235-
realpath_cache_add(path, len, tmp_resolved_path, tmp_resolved_path_len, info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY, *t);
1236-
}
1237-
memmove(path, tmp_resolved_path, tmp_resolved_path_len + 1);
1238-
1239-
return tmp_resolved_path_len;
1240-
}
1241-
/* }}} */
1242-
#endif
1243-
12441210
/* Resolve path relatively to state and put the real path into state */
12451211
/* returns 0 for ok, 1 for error */
12461212
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath) /* {{{ */
@@ -1368,27 +1334,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
13681334

13691335
add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]);
13701336
t = CWDG(realpath_cache_ttl) ? 0 : -1;
1371-
#ifdef ZEND_WIN32
1372-
if (CWD_EXPAND != use_realpath) {
1373-
size_t tmp_len = tsrm_win32_realpath_quick(resolved_path, path_length, &t);
1374-
if ((size_t)-1 != tmp_len) {
1375-
path_length = tmp_len;
1376-
} else {
1377-
DWORD err = GetLastError();
1378-
/* The access denied error can mean something completely else,
1379-
fallback to complicated way. */
1380-
if (CWD_REALPATH == use_realpath && ERROR_ACCESS_DENIED != err) {
1381-
SET_ERRNO_FROM_WIN32_CODE(err);
1382-
return 1;
1383-
}
1384-
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL);
1385-
}
1386-
} else {
1387-
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL);
1388-
}
1389-
#else
13901337
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL);
1391-
#endif
13921338

13931339
if (path_length == (size_t)-1) {
13941340
errno = ENOENT;

0 commit comments

Comments
 (0)