From: Vsevolod Stakhov Date: Fri, 30 Jul 2021 10:20:49 +0000 (+0100) Subject: [Minor] Try to deal with urls with backslashes in path X-Git-Tag: 3.0~71 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8b66801d1a9a82fde251b321945091a153eeadbb;p=thirdparty%2Frspamd.git [Minor] Try to deal with urls with backslashes in path --- diff --git a/src/libserver/url.c b/src/libserver/url.c index ce98f0961b..139252df4e 100644 --- a/src/libserver/url.c +++ b/src/libserver/url.c @@ -1165,7 +1165,7 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len, st = parse_port; c = p + 1; } - else if (*p == '/') { + else if (*p == '/' || *p == '\\') { st = parse_path; c = p + 1; } @@ -1309,11 +1309,11 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len, /* Too large domain */ goto out; } - if (t == '/' || t == ':' || t == '?' || t == '#') { + if (t == '/' || t == '\\' || t == ':' || t == '?' || t == '#') { if (p - c == 0) { goto out; } - if (t == '/') { + if (t == '/' || t == '\\') { SET_U (u, UF_HOST); st = parse_suffix_slash; } @@ -1463,7 +1463,7 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len, } break; case parse_port: - if (t == '/') { + if (t == '/' || t == '\\') { pt = strtoul (c, NULL, 10); if (pt == 0 || pt > 65535) { goto out; @@ -1515,7 +1515,7 @@ rspamd_web_parse (struct http_parser_url *u, const gchar *str, gsize len, p++; break; case parse_suffix_slash: - if (t != '/') { + if (t != '/' && t != '\\') { c = p; st = parse_path; } diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua index 282d792908..58dfada00f 100644 --- a/test/lua/unit/url.lua +++ b/test/lua/unit/url.lua @@ -138,7 +138,11 @@ context("URL check functions", function() }}, {"http://@@example.com", true, { user = "@", host = "example.com" - }} + }}, + {"https://example.com\\_Resources\\ClientImages\\UserData?ol\\o#ololo\\", true, { + host = "example.com", path = "_Resources/ClientImages/UserData", + query = "ol\\o", fragment = "ololo\\", + }}, } -- Some cases from https://code.google.com/p/google-url/source/browse/trunk/src/url_canon_unittest.cc