]> source.dussan.org Git - rspamd.git/commitdiff
[Test] More test cases
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 8 Jan 2017 18:37:07 +0000 (18:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sun, 8 Jan 2017 18:59:56 +0000 (18:59 +0000)
src/libutil/http.c
test/lua/unit/url.lua

index fdc9d1294a07da5a23119c13cb731fdbd5540da8..a981d1f41565dbc2efba287e42f9d37b508a1a2b 100644 (file)
@@ -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++ = '/';
index 991c6d0d07126e0fd25cc8ac2e388f017b2634b1..879386bba7b2d8aa83df84ef2ffe668e12d1a0a8 100644 (file)
@@ -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])