diff options
| author | Russell Belfer <rb@github.com> | 2013-09-03 12:27:56 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-09-03 12:27:56 -0700 |
| commit | 37fc44ddff9d8d41e3a8c29c8ce06a253a6bc20f (patch) | |
| tree | 680c514cdaf918dbb0443cb92e96e81127fa0a8f /src/path.c | |
| parent | b595b385dfbed63146f61185f1074d1334432bdd (diff) | |
| parent | 6d9a6c5cecebfaaecb4c39d002c8e0cdd26c4b85 (diff) | |
| download | libgit2-37fc44ddff9d8d41e3a8c29c8ce06a253a6bc20f.tar.gz | |
Merge pull request #1825 from nvloff/resolve_relative
path: properly resolve relative paths
Diffstat (limited to 'src/path.c')
| -rw-r--r-- | src/path.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/path.c b/src/path.c index a753a734d..50a990b27 100644 --- a/src/path.c +++ b/src/path.c @@ -646,12 +646,33 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling) /* do nothing with singleton dot */; else if (len == 2 && from[0] == '.' && from[1] == '.') { - while (to > base && to[-1] == '/') to--; - while (to > base && to[-1] != '/') to--; - } + /* error out if trying to up one from a hard base */ + if (to == base && ceiling != 0) { + giterr_set(GITERR_INVALID, + "Cannot strip root component off url"); + return -1; + } + + /* no more path segments to strip, + * use '../' as a new base path */ + if (to == base) { + if (*next == '/') + len++; - else { - if (*next == '/') + if (to != from) + memmove(to, from, len); + + to += len; + /* this is now the base, can't back up from a + * relative prefix */ + base = to; + } else { + /* back up a path segment */ + while (to > base && to[-1] == '/') to--; + while (to > base && to[-1] != '/') to--; + } + } else { + if (*next == '/' && *from != '/') len++; if (to != from) |
