]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Implement ap_getparent() using ap_normalize_path().
authorYann Ylavic <ylavic@apache.org>
Mon, 22 Jun 2020 10:30:20 +0000 (10:30 +0000)
committerYann Ylavic <ylavic@apache.org>
Mon, 22 Jun 2020 10:30:20 +0000 (10:30 +0000)
It is functionaly the same as AP_NORMALIZE_ALLOW_RELATIVE flag, while
ap_normalize_path() is more efficient (single pass).

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879075 13f79535-47bb-0310-9956-ffa450edef68

server/util.c

index ba9551927b66e1d9735a54b904f4d6e6097e99ca..b92e27eb6f85961b5b24cdc154077c9264908082 100644 (file)
@@ -607,70 +607,9 @@ AP_DECLARE(int) ap_normalize_path(char *path, unsigned int flags)
  */
 AP_DECLARE(void) ap_getparents(char *name)
 {
-    char *next;
-    int l, w, first_dot;
-
-    /* Four paseses, as per RFC 1808 */
-    /* a) remove ./ path segments */
-    for (next = name; *next && (*next != '.'); next++) {
-    }
-
-    l = w = first_dot = next - name;
-    while (name[l] != '\0') {
-        if (name[l] == '.' && IS_SLASH(name[l + 1])
-            && (l == 0 || IS_SLASH(name[l - 1])))
-            l += 2;
-        else
-            name[w++] = name[l++];
-    }
-
-    /* b) remove trailing . path, segment */
-    if (w == 1 && name[0] == '.')
-        w--;
-    else if (w > 1 && name[w - 1] == '.' && IS_SLASH(name[w - 2]))
-        w--;
-    name[w] = '\0';
-
-    /* c) remove all xx/../ segments. (including leading ../ and /../) */
-    l = first_dot;
-
-    while (name[l] != '\0') {
-        if (name[l] == '.' && name[l + 1] == '.' && IS_SLASH(name[l + 2])
-            && (l == 0 || IS_SLASH(name[l - 1]))) {
-            int m = l + 3, n;
-
-            l = l - 2;
-            if (l >= 0) {
-                while (l >= 0 && !IS_SLASH(name[l]))
-                    l--;
-                l++;
-            }
-            else
-                l = 0;
-            n = l;
-            while ((name[n] = name[m]))
-                (++n, ++m);
-        }
-        else
-            ++l;
-    }
-
-    /* d) remove trailing xx/.. segment. */
-    if (l == 2 && name[0] == '.' && name[1] == '.')
-        name[0] = '\0';
-    else if (l > 2 && name[l - 1] == '.' && name[l - 2] == '.'
-             && IS_SLASH(name[l - 3])) {
-        l = l - 4;
-        if (l >= 0) {
-            while (l >= 0 && !IS_SLASH(name[l]))
-                l--;
-            l++;
-        }
-        else
-            l = 0;
-        name[l] = '\0';
-    }
+    (void)ap_normalize_path(name, AP_NORMALIZE_ALLOW_RELATIVE);
 }
+
 AP_DECLARE(void) ap_no2slash_ex(char *name, int is_fs_path)
 {