summaryrefslogtreecommitdiff
path: root/file_io
diff options
context:
space:
mode:
authorWilliam A. Rowe Jr <wrowe@apache.org>2006-07-24 05:53:31 +0000
committerWilliam A. Rowe Jr <wrowe@apache.org>2006-07-24 05:53:31 +0000
commit14480043efcb1f25094682c92afafb0e8d5edd22 (patch)
tree7171b923e4e702887a3ad37add19fa925696a164 /file_io
parent9ded776deae227276d2460187cae0718aac32524 (diff)
downloadapr-14480043efcb1f25094682c92afafb0e8d5edd22.tar.gz
Solve svn issue 1869, avoid replacing previous ../ segments when multiple ../../.. patterns are present. This patch also normalizes the .. path seperators to use the same rules as normal paths, that is, if it's NATIVE use '\' (previous behavior), and (new behavior) if TRUENAME not NATIVE, use '/', otherwise the given slash. Adds no trailing slash if none was present on input. Solved with hints from Lieven Govaerts <lgo mobsol.be>. Resolves test fail identified by test/testnames.c commit 424831 git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@424915 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io')
-rw-r--r--file_io/win32/filepath.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/file_io/win32/filepath.c b/file_io/win32/filepath.c
index 1912a1c80..602cbc648 100644
--- a/file_io/win32/filepath.c
+++ b/file_io/win32/filepath.c
@@ -677,16 +677,22 @@ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
/* Otherwise this is simply a noop, above root is root.
*/
}
- else if (pathlen == 0 ||
- (pathlen >= 3 && (pathlen == 3
- || path[pathlen - 4] == ':')
- && path[pathlen - 3] == '.'
- && path[pathlen - 2] == '.'
- && (path[pathlen - 1] == '/'
- || path[pathlen - 1] == '\\')))
+ else if (pathlen == 0
+ || (pathlen >= 3
+ && (pathlen == 3
+ || path[pathlen - 4] == ':'
+ || path[pathlen - 4] == '/'
+ || path[pathlen - 4] == '\\')
+ && path[pathlen - 3] == '.'
+ && path[pathlen - 2] == '.'
+ && (path[pathlen - 1] == '/'
+ || path[pathlen - 1] == '\\')))
{
- /* Path is already backpathed or empty, if the
- * APR_FILEPATH_SECUREROOTTEST.was given die now.
+ /* Verified path is empty, exactly "..[/\]", or ends
+ * in "[:/\]..[/\]" - these patterns we will not back
+ * over since they aren't 'prior segements'.
+ *
+ * If APR_FILEPATH_SECUREROOTTEST.was given, die now.
*/
if (flags & APR_FILEPATH_SECUREROOTTEST)
return APR_EABOVEROOT;
@@ -695,9 +701,13 @@ APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
*/
if (pathlen + 3 >= sizeof(path))
return APR_ENAMETOOLONG;
- memcpy(path + pathlen, ((flags & APR_FILEPATH_NATIVE)
- ? "..\\" : "../"), 3);
- pathlen += 3;
+ path[pathlen++] = '.';
+ path[pathlen++] = '.';
+ if (addpath[segend]) {
+ path[pathlen++] = ((flags & APR_FILEPATH_NATIVE)
+ ? '\\' : ((flags & APR_FILEPATH_TRUENAME)
+ ? '/' : addpath[segend]));
+ }
/* The 'root' part of this path now includes the ../ path,
* because that backpath will not be parsed by the truename
* code below.