commit 202c18c: [Minor] Improve rspamd_url structure layout and remove `raw` field

Vsevolod Stakhov vsevolod at highsecure.ru
Wed Apr 14 15:21:04 UTC 2021


Author: Vsevolod Stakhov
Date: 2021-04-14 13:58:58 +0100
URL: https://github.com/rspamd/rspamd/commit/202c18cb66b7cf16ecfe6542580e38b7e3c4bab6

[Minor] Improve rspamd_url structure layout and remove `raw` field

---
 src/libserver/url.c | 41 ++++++++++++++++++++++-------------------
 src/libserver/url.h | 31 ++++++++++++++++---------------
 src/lua/lua_url.c   |  2 +-
 3 files changed, 39 insertions(+), 35 deletions(-)

diff --git a/src/libserver/url.c b/src/libserver/url.c
index 1548c4535..fb4b4da94 100644
--- a/src/libserver/url.c
+++ b/src/libserver/url.c
@@ -428,22 +428,24 @@ const gchar *
 rspamd_url_strerror (int err)
 {
 	switch (err) {
-		case URI_ERRNO_OK:
-			return "Parsing went well";
-		case URI_ERRNO_EMPTY:
-			return "The URI string was empty";
-		case URI_ERRNO_INVALID_PROTOCOL:
-			return "No protocol was found";
-		case URI_ERRNO_BAD_FORMAT:
-			return "Bad URL format";
-		case URI_ERRNO_BAD_ENCODING:
-			return "Invalid symbols encoded";
-		case URI_ERRNO_INVALID_PORT:
-			return "Port number is bad";
-		case URI_ERRNO_TLD_MISSING:
-			return "TLD part is not detected";
-		case URI_ERRNO_HOST_MISSING:
-			return "Host part is missing";
+	case URI_ERRNO_OK:
+		return "Parsing went well";
+	case URI_ERRNO_EMPTY:
+		return "The URI string was empty";
+	case URI_ERRNO_INVALID_PROTOCOL:
+		return "No protocol was found";
+	case URI_ERRNO_BAD_FORMAT:
+		return "Bad URL format";
+	case URI_ERRNO_BAD_ENCODING:
+		return "Invalid symbols encoded";
+	case URI_ERRNO_INVALID_PORT:
+		return "Port number is bad";
+	case URI_ERRNO_TLD_MISSING:
+		return "TLD part is not detected";
+	case URI_ERRNO_HOST_MISSING:
+		return "Host part is missing";
+	case URI_ERRNO_TOO_LONG:
+		return "URL is too long";
 	}
 
 	return NULL;
@@ -2187,6 +2189,10 @@ rspamd_url_parse (struct rspamd_url *uri,
 		return URI_ERRNO_EMPTY;
 	}
 
+	if (len >= G_MAXUINT16 / 2) {
+		return URI_ERRNO_TOO_LONG;
+	}
+
 	p = uristring;
 	uri->protocol = PROTOCOL_UNKNOWN;
 
@@ -2219,9 +2225,6 @@ rspamd_url_parse (struct rspamd_url *uri,
 		len = end - uristring;
 	}
 
-	uri->raw = p;
-	uri->rawlen = len;
-
 	if (flags & RSPAMD_URL_FLAG_MISSINGSLASHES) {
 		len += 2;
 		uri->string = rspamd_mempool_alloc (pool, len + 1);
diff --git a/src/libserver/url.h b/src/libserver/url.h
index 59485ab9a..0a36ca17b 100644
--- a/src/libserver/url.h
+++ b/src/libserver/url.h
@@ -46,20 +46,25 @@ struct rspamd_url_tag {
 };
 
 struct rspamd_url {
-	gchar *raw;
 	gchar *string;
 
+	gchar *visible_part;
+	struct rspamd_url *phished_url;
+
+	guint32 flags;
+
 	guint16 protocol;
+	guint16 protocollen;
 	guint16 port;
 
-	guint usershift;
-	guint hostshift;
-	guint datashift;
-	guint queryshift;
-	guint fragmentshift;
-	guint tldshift;
+	guint16 usershift;
+	guint16 hostshift;
+	guint16 datashift;
+	guint16 queryshift;
+	guint16 fragmentshift;
+	guint16 tldshift;
+
 
-	guint16 protocollen;
 	guint16 userlen;
 	guint16 hostlen;
 	guint16 datalen;
@@ -68,12 +73,7 @@ struct rspamd_url {
 	guint16 tldlen;
 	guint16 count;
 
-	guint urllen;
-	guint rawlen;
-	guint32 flags;
-
-	gchar *visible_part;
-	struct rspamd_url *phished_url;
+	guint16 urllen;
 };
 
 #define rspamd_url_user(u) ((u)->userlen > 0 ? (u)->string + (u)->usershift : NULL)
@@ -95,7 +95,8 @@ enum uri_errno {
 	URI_ERRNO_BAD_ENCODING, /* Bad characters encoding */
 	URI_ERRNO_BAD_FORMAT,
 	URI_ERRNO_TLD_MISSING,
-	URI_ERRNO_HOST_MISSING
+	URI_ERRNO_HOST_MISSING,
+	URI_ERRNO_TOO_LONG,
 };
 
 enum rspamd_url_protocol {
diff --git a/src/lua/lua_url.c b/src/lua/lua_url.c
index c2dade139..d77d4b27d 100644
--- a/src/lua/lua_url.c
+++ b/src/lua/lua_url.c
@@ -348,7 +348,7 @@ lua_url_get_raw (lua_State *L)
 	struct rspamd_lua_url *url = lua_check_url (L, 1);
 
 	if (url != NULL) {
-		lua_pushlstring (L, url->url->raw, url->url->rawlen);
+		lua_pushlstring (L, url->url->string, url->url->urllen);
 	}
 	else {
 		lua_pushnil (L);


More information about the Commits mailing list