diff options
author | Yann Ylavic <ylavic@apache.org> | 2020-06-22 12:30:20 +0200 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2020-06-22 12:30:20 +0200 |
commit | 4004ce236575d8b0a8c0d001352742055a8c76c3 (patch) | |
tree | b22f5af774cc6b6bcccb584c6da8ed25ede61b0b /server | |
parent | Add ap_normalize_path() to replace ap_getparents() (with options). (diff) | |
download | apache2-4004ce236575d8b0a8c0d001352742055a8c76c3.tar.xz apache2-4004ce236575d8b0a8c0d001352742055a8c76c3.zip |
Implement ap_getparent() using ap_normalize_path().
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
Diffstat (limited to 'server')
-rw-r--r-- | server/util.c | 65 |
1 files changed, 2 insertions, 63 deletions
diff --git a/server/util.c b/server/util.c index ba9551927b..b92e27eb6f 100644 --- a/server/util.c +++ b/server/util.c @@ -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) { |