Make the retry_include_ip_address smtp transport option expanded. Bug 1545
[exim.git] / src / src / spam.c
index 3d38d99dd6a7747f1d527a70eafc7ef9cf7fd471..76bf7d67fc8bcc70988cdf7bf358f96d3925099c 100644 (file)
@@ -1,5 +1,3 @@
-/* $Cambridge: exim/src/src/spam.c,v 1.18 2010/06/05 11:13:30 pdp Exp $ */
-
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/
@@ -22,14 +20,16 @@ int spam_ok = 0;
 int spam_rc = 0;
 uschar *prev_spamd_address_work = NULL;
 
-int spam(uschar **listptr) {
+int
+spam(uschar **listptr)
+{
   int sep = 0;
   uschar *list = *listptr;
   uschar *user_name;
   uschar user_name_buffer[128];
   unsigned long mbox_size;
   FILE *mbox_file;
-  int spamd_sock;
+  int spamd_sock = -1;
   uschar spamd_buffer[32600];
   int i, j, offset, result;
   uschar spamd_version[8];
@@ -129,7 +129,8 @@ int spam(uschar **listptr) {
         (spamd_address_container *)store_get(sizeof(spamd_address_container));
 
       /* grok spamd address and port */
-      if( sscanf(CS address, "%s %u", this_spamd->tcp_addr, &(this_spamd->tcp_port)) != 2 ) {
+      if (sscanf(CS address, "%23s %u", this_spamd->tcp_addr, &(this_spamd->tcp_port)) != 2)
+        {
         log_write(0, LOG_MAIN,
           "spam acl condition: warning - invalid spamd address: '%s'", address);
         continue;
@@ -222,6 +223,14 @@ int spam(uschar **listptr) {
 
   }
 
+  if (spamd_sock == -1) {
+    log_write(0, LOG_MAIN|LOG_PANIC,
+        "programming fault, spamd_sock unexpectedly unset");
+    (void)fclose(mbox_file);
+    (void)close(spamd_sock);
+    return DEFER;
+  }
+
   /* now we are connected to spamd on spamd_sock */
   (void)string_format(spamd_buffer,
            sizeof(spamd_buffer),
@@ -280,7 +289,7 @@ again:
             "spam acl condition: %s on spamd socket", strerror(errno));
         else {
           if (time(NULL) - start < SPAMD_TIMEOUT)
-          goto again;
+            goto again;
           log_write(0, LOG_MAIN|LOG_PANIC,
             "spam acl condition: timed out writing spamd socket");
         }