From fb3cfd2368694af6d4c1c15efd11f4798c015219 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 31 Jul 2018 15:48:24 +0100 Subject: [PATCH] [Fix] Avoid one extra byte writing --- src/libserver/url.c | 2 +- test/lua/unit/url.lua | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libserver/url.c b/src/libserver/url.c index 019a4ff36..653cc3570 100644 --- a/src/libserver/url.c +++ b/src/libserver/url.c @@ -1652,7 +1652,7 @@ rspamd_url_parse (struct rspamd_url *uri, gchar *uristring, gsize len, memcpy (uri->string + u.field_data[UF_SCHEMA].len, "://", 3); rspamd_strlcpy (uri->string + u.field_data[UF_SCHEMA].len + 3, p + u.field_data[UF_SCHEMA].len + 1, - len - 1 - u.field_data[UF_SCHEMA].len); + len - 2 - u.field_data[UF_SCHEMA].len); /* Compensate slashes added */ for (i = UF_SCHEMA + 1; i < UF_MAX; i++) { if (u.field_set & (1 << i)) { diff --git a/test/lua/unit/url.lua b/test/lua/unit/url.lua index ccde222f8..902744c2e 100644 --- a/test/lua/unit/url.lua +++ b/test/lua/unit/url.lua @@ -95,6 +95,9 @@ context("URL check functions", function() {"http://twitter.com#test", true, { host = 'twitter.com', fragment = 'test' }}, + {"http:www.twitter.com#test", true, { + host = 'www.twitter.com', fragment = 'test' + }}, } -- Some cases from https://code.google.com/p/google-url/source/browse/trunk/src/url_canon_unittest.cc -- 2.39.5