]> granicus.if.org Git - apache/commitdiff
Optimization for ap_getparents: skip past all the leading
authorBrian Pane <brianp@apache.org>
Mon, 3 Dec 2001 00:49:28 +0000 (00:49 +0000)
committerBrian Pane <brianp@apache.org>
Mon, 3 Dec 2001 00:49:28 +0000 (00:49 +0000)
characters of the path that aren't '.' rather than copying
those bytes onto themselves

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

server/util.c

index 71b42f8b66f15a58cc198a2ce4ba48d8719cd88c..beda6b43903a9f18e36aeaa6732c2af542e69688 100644 (file)
@@ -476,12 +476,15 @@ AP_DECLARE(char *) ap_pregsub(apr_pool_t *p, const char *input, const char *sour
  */
 AP_DECLARE(void) ap_getparents(char *name)
 {
-    int l, w;
+    char *next;
+    int l, w, first_dot;
 
     /* Four paseses, as per RFC 1808 */
     /* a) remove ./ path segments */
-
-    for (l = 0, w = 0; name[l] != '\0';) {
+    for (next = name; *next && (*next != '.'); next++) {
+    }
+    l = w = first_dot = next - name;
+    while (name[l] != '\0') {
        if (name[l] == '.' && name[l + 1] == '/' && (l == 0 || name[l - 1] == '/'))
            l += 2;
        else
@@ -496,7 +499,7 @@ AP_DECLARE(void) ap_getparents(char *name)
     name[w] = '\0';
 
     /* c) remove all xx/../ segments. (including leading ../ and /../) */
-    l = 0;
+    l = first_dot;
 
     while (name[l] != '\0') {
        if (name[l] == '.' && name[l + 1] == '.' && name[l + 2] == '/' &&