Improved the depth calculation in sanitize_path() so that it properly
authorWayne Davison <wayned@samba.org>
Sun, 23 May 2004 23:46:56 +0000 (23:46 +0000)
committerWayne Davison <wayned@samba.org>
Sun, 23 May 2004 23:46:56 +0000 (23:46 +0000)
handles a trailing slash, a leading slash, and an empty string.

util.c

diff --git a/util.c b/util.c
index 2212723..4b46b35 100644 (file)
--- a/util.c
+++ b/util.c
@@ -707,9 +707,12 @@ void sanitize_path(char *p, char *reldir)
        int allowdotdot = 0;
 
        if (reldir) {
-               depth++;
+               int new_component = 1;
                while (*reldir) {
-                       if (*reldir++ == '/') {
+                       if (*reldir++ == '/')
+                               new_component = 1;
+                       else if (new_component) {
+                               new_component = 0;
                                depth++;
                        }
                }