Skip to content

Commit

Permalink
Merge branch 'PHP-7.3'
Browse files Browse the repository at this point in the history
* PHP-7.3:
  Fixed bug #77317 __DIR__, __FILE__, realpath() reveal physical path for subst virtual drive
  • Loading branch information
weltling committed Dec 26, 2018
2 parents 95d8e05 + 199914b commit f44d53b
Showing 1 changed file with 0 additions and 54 deletions.
54 changes: 0 additions & 54 deletions Zend/zend_virtual_cwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,40 +957,6 @@ static size_t tsrm_realpath_r(char *path, size_t start, size_t len, int *ll, tim
}
/* }}} */

#ifdef ZEND_WIN32
static size_t tsrm_win32_realpath_quick(char *path, size_t len, time_t *t) /* {{{ */
{
char tmp_resolved_path[MAXPATHLEN];
int tmp_resolved_path_len;
BY_HANDLE_FILE_INFORMATION info;
realpath_cache_bucket *bucket;

if (!*t) {
*t = time(0);
}

if (CWDG(realpath_cache_size_limit) && (bucket = realpath_cache_find(path, len, *t)) != NULL) {
memcpy(path, bucket->realpath, bucket->realpath_len + 1);
return bucket->realpath_len;
}

if (!php_win32_ioutil_realpath_ex0(path, tmp_resolved_path, &info)) {
DWORD err = GetLastError();
SET_ERRNO_FROM_WIN32_CODE(err);
return (size_t)-1;
}

tmp_resolved_path_len = strlen(tmp_resolved_path);
if (CWDG(realpath_cache_size_limit)) {
realpath_cache_add(path, len, tmp_resolved_path, tmp_resolved_path_len, info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY, *t);
}
memmove(path, tmp_resolved_path, tmp_resolved_path_len + 1);

return tmp_resolved_path_len;
}
/* }}} */
#endif

/* Resolve path relatively to state and put the real path into state */
/* returns 0 for ok, 1 for error */
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath) /* {{{ */
Expand Down Expand Up @@ -1118,27 +1084,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func

add_slash = (use_realpath != CWD_REALPATH) && path_length > 0 && IS_SLASH(resolved_path[path_length-1]);
t = CWDG(realpath_cache_ttl) ? 0 : -1;
#ifdef ZEND_WIN32
if (CWD_EXPAND != use_realpath) {
size_t tmp_len = tsrm_win32_realpath_quick(resolved_path, path_length, &t);
if ((size_t)-1 != tmp_len) {
path_length = tmp_len;
} else {
DWORD err = GetLastError();
/* The access denied error can mean something completely else,
fallback to complicated way. */
if (CWD_REALPATH == use_realpath && ERROR_ACCESS_DENIED != err) {
SET_ERRNO_FROM_WIN32_CODE(err);
return 1;
}
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL);
}
} else {
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL);
}
#else
path_length = tsrm_realpath_r(resolved_path, start, path_length, &ll, &t, use_realpath, 0, NULL);
#endif

if (path_length == (size_t)-1) {
errno = ENOENT;
Expand Down

0 comments on commit f44d53b

Please sign in to comment.