]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Improve rspamd_url structure layout and remove `raw` field
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 14 Apr 2021 12:58:58 +0000 (13:58 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 14 Apr 2021 12:58:58 +0000 (13:58 +0100)
src/libserver/url.c
src/libserver/url.h
src/lua/lua_url.c

index 1548c4535f3b27de505824d02f3e1d2428972e37..fb4b4da94913191c4f4131395e8276ce47501f00 100644 (file)
@@ -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);
index 59485ab9a368d1dba0f4c21f17bf3ac0bdbe8c33..0a36ca17b0cae7fc314841c3fbbbb94ba66b20f6 100644 (file)
@@ -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 {
index c2dade139d40c6ddc1b1d66e947c1f044c132ddd..d77d4b27d41d5e5ad3d439f4c86e146b531b40a7 100644 (file)
@@ -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);