summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Gutmans <andi@php.net>2000-06-28 17:30:30 +0000
committerAndi Gutmans <andi@php.net>2000-06-28 17:30:30 +0000
commitda8843aa55cf7b688fd93d85f51e13d0ea764d27 (patch)
treebf65aa91385915fad6a5a5b270bd5bb0395ac2e6
parentb952c2c95aac3f0c3cf5256bcdd1a56a8ea43d55 (diff)
downloadphp-git-da8843aa55cf7b688fd93d85f51e13d0ea764d27.tar.gz
- Fix problem with VIRTUAL_DIR and relative paths containing ..
-rw-r--r--main/php_virtual_cwd.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/main/php_virtual_cwd.c b/main/php_virtual_cwd.c
index 392f1444ad..3fd4d5542c 100644
--- a/main/php_virtual_cwd.c
+++ b/main/php_virtual_cwd.c
@@ -281,9 +281,30 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
#ifndef ZEND_WIN32
if (strstr(path, "..")) {
/* If .. is found then we need to resolve real path as the .. code doesn't work with symlinks */
- if (realpath(path, resolved_path)) {
- path = resolved_path;
- path_length = strlen(path);
+ if (IS_ABSOLUTE_PATH(path, path_length)) {
+ if (realpath(path, resolved_path)) {
+ path = resolved_path;
+ path_length = strlen(path);
+ }
+ } else { /* Concat current directory with relative path and then run realpath() on it */
+ char *tmp;
+ char *ptr;
+
+ ptr = tmp = (char *) malloc(state->cwd_length+path_length+sizeof("/"));
+ if (!tmp) {
+ return 1;
+ }
+ memcpy(ptr, state->cwd, state->cwd_length);
+ ptr += state->cwd_length;
+ *ptr++ = DEFAULT_SLASH;
+ memcpy(ptr, path, path_length);
+ ptr += path_length;
+ *ptr = '\0';
+ if (realpath(tmp, resolved_path)) {
+ path = resolved_path;
+ path_length = strlen(path);
+ }
+ free(tmp);
}
}
#endif