]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Url: Fix parsing of numeric urls with a port
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Apr 2021 10:58:28 +0000 (11:58 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 12 Apr 2021 10:58:28 +0000 (11:58 +0100)
src/libserver/url.c
src/lua/lua_url.c

index 8183213b66493b9001620221ef05f7b7c8a17bec..1548c4535f3b27de505824d02f3e1d2428972e37 100644 (file)
@@ -1715,11 +1715,16 @@ rspamd_url_regen_from_inet_addr (struct rspamd_url *uri, const void *addr, int a
                slen += INET6_ADDRSTRLEN;
        }
 
+       if (uri->flags & RSPAMD_URL_FLAG_HAS_PORT) {
+               slen += sizeof ("65535") - 1;
+       }
+
        /* Allocate new string to build it from IP */
        strbuf = rspamd_mempool_alloc (pool, slen + 1);
        r += rspamd_snprintf (strbuf + r, slen - r, "%*s",
                        (gint)(uri->hostshift),
                        uri->string);
+
        uri->hostshift = r;
        uri->tldshift = r;
        start_offset = strbuf + r;
@@ -1730,6 +1735,12 @@ rspamd_url_regen_from_inet_addr (struct rspamd_url *uri, const void *addr, int a
        uri->flags |= RSPAMD_URL_FLAG_NUMERIC;
 
        /* Reconstruct URL */
+       if (uri->flags & RSPAMD_URL_FLAG_HAS_PORT) {
+               p = strbuf + r;
+               start_offset = p + 1;
+               r += rspamd_snprintf (strbuf + r, slen - r, ":%ud",
+                               (unsigned int)uri->port);
+       }
        if (uri->datalen > 0) {
                p = strbuf + r;
                start_offset = p + 1;
index 37bccd1b2cb609669f12d6d80ce941d3d3b0d1b4..ad938c052911fe420143dab25410754bedc3c043 100644 (file)
@@ -719,6 +719,16 @@ lua_url_to_table (lua_State *L)
        return 1;
 }
 
+static rspamd_mempool_t *static_lua_url_pool;
+
+RSPAMD_CONSTRUCTOR(rspamd_urls_static_pool_ctor) {
+       static_lua_url_pool = rspamd_mempool_new (rspamd_mempool_suggest_size (),
+                       "static_lua_url", 0);
+}
+
+RSPAMD_DESTRUCTOR(rspamd_urls_static_pool_dtor) {
+       rspamd_mempool_delete (static_lua_url_pool);
+}
 
 /***
  * @function url.create([mempool,] str, [{flags_table}])
@@ -742,15 +752,11 @@ lua_url_create (lua_State *L)
        }
        else {
                own_pool = TRUE;
-               pool = rspamd_mempool_new (rspamd_mempool_suggest_size (), "url", 0);
+               pool = static_lua_url_pool;
                text = luaL_checklstring (L, 1, &length);
        }
 
        if (pool == NULL || text == NULL) {
-               if (own_pool && pool) {
-                       rspamd_mempool_delete (pool);
-               }
-
                return luaL_error (L, "invalid arguments");
        }
        else {
@@ -783,10 +789,6 @@ lua_url_create (lua_State *L)
                }
        }
 
-       if (own_pool && pool) {
-               rspamd_mempool_delete (pool);
-       }
-
        return 1;
 }