From fbb1cb12a6e0e17a143593adf60483ad1e70fbca Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 8 Jan 2017 18:37:07 +0000 Subject: [PATCH] [Test] More test cases --- src/libutil/http.c | 18 +++++++++++++----- test/lua/unit/url.lua | 10 +++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/libutil/http.c b/src/libutil/http.c index fdc9d1294..a981d1f41 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -3549,11 +3549,7 @@ rspamd_http_normalize_path_inplace (gchar *path, gsize len, gsize *nlen) } else { /* We have something like bla../, so we need to copy it as is */ - - if (slash) { - *o ++ = '/'; - } - if (dot && p > dot) { + if (o > path && dot && p > dot) { memcpy (o, dot, p - dot); o += p - dot; } @@ -3612,6 +3608,18 @@ rspamd_http_normalize_path_inplace (gchar *path, gsize len, gsize *nlen) o = (gchar *)slash; } } + else { + /* Corner case */ + if (o == path) { + *o++ = '/'; + } + else { + if (dot && p > dot) { + memmove (o, dot, p - dot); + o += p - dot; + } + } + } break; case st_got_slash: *o++ = '/'; diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua index 991c6d0d0..879386bba 100644 --- a/test/lua/unit/url.lua +++ b/test/lua/unit/url.lua @@ -135,10 +135,18 @@ context("URL check functions", function() {"/foo/../../..", "/"}, {"/foo/../../../ton", "/ton"}, {"////../..", "/"}, + {"./", ""}, + {"/./", "/"}, + {"/./././././././", "/"}, + {"/", "/"}, + {"/a/b", "/a/b"}, + {"/a/b/", "/a/b/"}, + {"..", "/"}, + {"/../", "/"}, + {"../", "/"}, } for _,v in ipairs(cases) do - print(v[1]) local buf = ffi.new("uint8_t[?]", #v[1]) local sizbuf = ffi.new("size_t[1]") ffi.copy(buf, v[1], #v[1]) -- 2.39.5