]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Remove extra code for IP urls in surbl module
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Nov 2015 14:50:57 +0000 (14:50 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Nov 2015 14:50:57 +0000 (14:50 +0000)
src/plugins/surbl.c

index 2b8fc3571913dfe1d876385ce0fc8c76f9e92858..58083a9802c31c20c848333ba1b93db3bee0de3e 100644 (file)
@@ -687,11 +687,11 @@ format_surbl_request (rspamd_mempool_t * pool,
        struct rspamd_url *url)
 {
        GHashTable *t;
-       gchar *result = NULL, num_buf[sizeof("18446744073709551616")];
+       gchar *result = NULL;
        const gchar *p, *dots[MAX_LEVELS];
-       gint len, slen, r, i, dots_num = 0, level = MAX_LEVELS;
-       gboolean is_numeric = TRUE, found_exception = FALSE;
-       guint64 ip_num;
+       gint r, i, dots_num = 0, level = MAX_LEVELS;
+       gsize slen, len;
+       gboolean found_exception = FALSE;
        rspamd_ftok_t f;
 
        if (G_LIKELY (suffix != NULL)) {
@@ -703,10 +703,10 @@ format_surbl_request (rspamd_mempool_t * pool,
        else {
                g_assert_not_reached ();
        }
+
        len = hostname->len + slen + 2;
 
        p = hostname->begin;
-       is_numeric = url->flags & RSPAMD_URL_FLAG_NUMERIC;
 
        while (p - hostname->begin < (gint)hostname->len && dots_num < MAX_LEVELS) {
                if (*p == '.') {
@@ -718,7 +718,7 @@ format_surbl_request (rspamd_mempool_t * pool,
        }
 
        /* Check for numeric expressions */
-       if (is_numeric && dots_num == 3) {
+       if (url->flags & RSPAMD_URL_FLAG_NUMERIC) {
                /* This is ip address */
                if (suffix != NULL && (suffix->options & SURBL_OPTION_NOIP) != 0) {
                        /* Ignore such requests */
@@ -726,51 +726,26 @@ format_surbl_request (rspamd_mempool_t * pool,
                                        suffix->symbol);
                        return NULL;
                }
-               result = rspamd_mempool_alloc (pool, len);
-               r = rspamd_snprintf (result, len, "%*s.%*s.%*s.%*s",
-                               (gint)(hostname->len - (dots[2] - hostname->begin + 1)),
-                               dots[2] + 1,
-                               (gint)(dots[2] - dots[1] - 1),
-                               dots[1] + 1,
-                               (gint)(dots[1] - dots[0] - 1),
-                               dots[0] + 1,
-                               (gint)(dots[0] - hostname->begin),
-                               hostname->begin);
-       }
-       else if (is_numeric && dots_num == 0) {
-               /* This is number */
-               if (suffix != NULL && (suffix->options & SURBL_OPTION_NOIP) != 0) {
-                       /* Ignore such requests */
-                       msg_info_pool ("ignore request of ip url for list %s",
-                                       suffix->symbol);
-                       return NULL;
+
+               if (dots_num == 3) {
+                       /* IPv4 address */
+                       result = rspamd_mempool_alloc (pool, len);
+                       r = rspamd_snprintf (result, len, "%*s.%*s.%*s.%*s",
+                                       (gint) (hostname->len - (dots[2] - hostname->begin + 1)),
+                                       dots[2] + 1,
+                                       (gint) (dots[2] - dots[1] - 1),
+                                       dots[1] + 1,
+                                       (gint) (dots[1] - dots[0] - 1),
+                                       dots[0] + 1,
+                                       (gint) (dots[0] - hostname->begin),
+                                       hostname->begin);
                }
-               rspamd_strlcpy (num_buf, hostname->begin,
-                       MIN (hostname->len + 1, sizeof (num_buf)));
-               errno = 0;
-               ip_num = strtoull (num_buf, NULL, 10);
-               if (errno != 0) {
-                       msg_info_pool ("cannot convert ip to number '%s': %s",
-                               num_buf,
-                               strerror (errno));
-                       g_set_error (err, SURBL_ERROR, /* error domain */
-                               CONVERSION_ERROR,   /* error code */
-                               "URL cannot be decoded");
-                       return NULL;
+               else {
+                       /* Just pring ip as is */
+                       result = rspamd_mempool_alloc (pool, len);
+                       r = rspamd_snprintf (result, len, "%*s",
+                                       (gint)hostname->len, hostname->begin);
                }
-
-               len = sizeof ("255.255.255.255") + slen;
-               result = rspamd_mempool_alloc (pool, len);
-               /* Hack for bugged windows resolver */
-               ip_num &= 0xFFFFFFFF;
-               /* Get octets */
-               r = rspamd_snprintf (result,
-                               len,
-                               "%ud.%ud.%ud.%ud",
-                               (guint32) ip_num & 0x000000FF,
-                               (guint32) (ip_num & 0x0000FF00) >> 8,
-                               (guint32) (ip_num & 0x00FF0000) >> 16,
-                               (guint32) (ip_num & 0xFF000000) >> 24);
        }
        else {
                /* Not a numeric url */