diff src/dnsbl.cpp @ 284:896b9393d3f0 stable-6-0-39

Fix segfault caused by freeing unallocated memory
author Carl Byington <carl@five-ten-sg.com>
date Tue, 31 Dec 2013 10:44:15 -0800
parents e276180647ab
children 9bd5388bf469
line wrap: on
line diff
--- a/src/dnsbl.cpp	Tue Dec 24 08:22:01 2013 -0800
+++ b/src/dnsbl.cpp	Tue Dec 31 10:44:15 2013 -0800
@@ -1176,24 +1176,6 @@
     priv.client_name   = smfi_getsymval(ctx, (char*)"_");
     if (!priv.helo)         priv.helo          = strdup("unknown");
     if (priv.authenticated) priv.authenticated = strdup(priv.authenticated);
-    {
-        const char *uid = (priv.authenticated) ? priv.authenticated : priv.mailaddr;
-        if (priv.authenticated || dc.default_context->is_unauthenticated_limited(priv.mailaddr)) {
-            int hourly, daily;
-            add_auth_address(uid, hourly, daily, priv.ip);
-            int h_limit = dc.default_context->find_address_limit(uid);
-            int d_limit = dc.default_context->get_daily_address_multiple() * h_limit;
-            if (debug_syslog > 1) {
-                char msg[maxlen];
-                snprintf(msg, sizeof(msg), "connect for %s (%d %d addresses, %d %d limits)", uid, hourly, daily, h_limit, d_limit);
-                my_syslog(&priv, msg);
-            }
-            if ((hourly > h_limit) || (daily > d_limit)){
-                smfi_setreply(ctx, (char*)"550", (char*)"5.7.1", (char*)"unique connection ip address limit exceeded");
-                return SMFIS_REJECT;
-            }
-        }
-    }
     if (priv.client_name) {
         priv.client_name = strdup(priv.client_name);
         const char *p = strstr(priv.client_name, " [");
@@ -1221,6 +1203,22 @@
     if (dccifd_port) {
         priv.dccifd = new DccInterface(dccifd_port, &priv, priv.ip, priv.helo, priv.mailaddr);
     }
+    const char *uid = (priv.authenticated) ? priv.authenticated : priv.mailaddr;
+    if (priv.authenticated || dc.default_context->is_unauthenticated_limited(priv.mailaddr)) {
+        int hourly, daily;
+        add_auth_address(uid, hourly, daily, priv.ip);
+        int h_limit = dc.default_context->find_address_limit(uid);
+        int d_limit = dc.default_context->get_daily_address_multiple() * h_limit;
+        if (debug_syslog > 1) {
+            char msg[maxlen];
+            snprintf(msg, sizeof(msg), "connect for %s (%d %d addresses, %d %d limits)", uid, hourly, daily, h_limit, d_limit);
+            my_syslog(&priv, msg);
+        }
+        if ((hourly > h_limit) || (daily > d_limit)){
+            smfi_setreply(ctx, (char*)"550", (char*)"5.7.1", (char*)"unique connection ip address limit exceeded");
+            return SMFIS_REJECT;
+        }
+    }
     return SMFIS_CONTINUE;
 }