summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWayne Davison <wayned@samba.org>2004-08-12 10:13:45 +0000
committerWayne Davison <wayned@samba.org>2004-08-12 10:13:45 +0000
commit8e5f029e02a691ff05e5f221e421d7a4939ba528 (patch)
tree0cf99ba81e1b85289a718160d0ebd925b43912c9
parent2d41264e9ef645be0337ea64a398de2e563a4287 (diff)
downloadrsync-8e5f029e02a691ff05e5f221e421d7a4939ba528.tar.gz
rsync-8e5f029e02a691ff05e5f221e421d7a4939ba528.tar.bz2
rsync-8e5f029e02a691ff05e5f221e421d7a4939ba528.zip
One (hopefully) last change to the sanitize_path() code.
-rw-r--r--util.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/util.c b/util.c
index 5243c746..a2e8660b 100644
--- a/util.c
+++ b/util.c
@@ -781,25 +781,22 @@ char *sanitize_path(char *dest, const char *p, const char *rootdir, int depth)
}
if (*p == '.' && p[1] == '.' && (p[2] == '/' || p[2] == '\0')) {
/* ".." component followed by slash or end */
- if (depth > 0 && sanp == start) {
- /* allow depth levels of .. at the beginning */
- --depth;
- *sanp++ = *p++;
- *sanp++ = *p++;
- /* move virtual beginning to leave .. alone */
- start = sanp;
- continue;
- }
- p += 2;
- if (sanp != start) {
- /* back up sanp one level */
- --sanp; /* now pointing at slash */
- while (sanp > start && sanp[-1] != '/') {
- /* skip back up to slash */
- sanp--;
+ if (depth <= 0 || sanp != start) {
+ p += 2;
+ if (sanp != start) {
+ /* back up sanp one level */
+ --sanp; /* now pointing at slash */
+ while (sanp > start && sanp[-1] != '/') {
+ /* skip back up to slash */
+ sanp--;
+ }
}
+ continue;
}
- continue;
+ /* allow depth levels of .. at the beginning */
+ depth--;
+ /* move the virtual beginning to leave the .. alone */
+ start = sanp + 3;
}
/* copy one component through next slash */
while (*p && (*sanp++ = *p++) != '/') {}