diff options
-rw-r--r-- | main/fopen_wrappers.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/main/fopen_wrappers.c b/main/fopen_wrappers.c index fb39544f1f..7bcc9086fb 100644 --- a/main/fopen_wrappers.c +++ b/main/fopen_wrappers.c @@ -325,26 +325,31 @@ PHPAPI FILE *php_fopen_primary_script(void) } } else #endif + if (PG(doc_root) && path_info) { + length = strlen(PG(doc_root)); #ifdef PHP_WIN32 - if (PG(doc_root) && path_info && (IS_SLASH(*PG(doc_root)) - /* Check for absolute path. This should also use virtual cwd macros */ - || (PG(doc_root)[1] == ':' && IS_SLASH(PG(doc_root)[2]))) { + /* Check for absolute path. This should really use virtual cwd macros */ + if (IS_SLASH(*PG(doc_root) || (length >= 3 && PG(doc_root)[1] == ':' && IS_SLASH(PG(doc_root)[2]))) { #else - if (PG(doc_root) && path_info && IS_SLASH(*PG(doc_root))) { + if (IS_SLASH(*PG(doc_root))) { #endif - length = strlen(PG(doc_root)); - filename = emalloc(length + strlen(path_info) + 2); - if (filename) { - memcpy(filename, PG(doc_root), length); - if (!IS_SLASH(filename[length - 1])) /* length is never 0 */ - filename[length++] = DEFAULT_SLASH; - if (IS_SLASH(path_info[0])) - length--; - strcpy(filename + length, path_info); - STR_FREE(SG(request_info).path_translated); - SG(request_info).path_translated = filename; + length = strlen(PG(doc_root)); + filename = emalloc(length + strlen(path_info) + 2); + if (filename) { + memcpy(filename, PG(doc_root), length); + if (!IS_SLASH(filename[length - 1])) { /* length is never 0 */ + filename[length++] = DEFAULT_SLASH; + } + if (IS_SLASH(path_info[0])) { + length--; + } + strcpy(filename + length, path_info); + STR_FREE(SG(request_info).path_translated); + SG(request_info).path_translated = filename; + } } - } /* if doc_root && path_info */ + } /* if doc_root && path_info */ + if (!filename) { /* we have to free SG(request_info).path_translated here because php_destroy_request_info assumes that it will get |