You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by si...@apache.org on 2007/07/04 21:49:59 UTC

svn commit: r553314 - in /spamassassin/branches/3.2: MANIFEST spamc/libspamc.c

Author: sidney
Date: Wed Jul  4 12:49:58 2007
New Revision: 553314

URL: http://svn.apache.org/viewvc?view=rev&rev=553314
Log:
bug5462: fix spamc -H randomisation that was broken

Modified:
    spamassassin/branches/3.2/MANIFEST
    spamassassin/branches/3.2/spamc/libspamc.c

Modified: spamassassin/branches/3.2/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/MANIFEST?view=diff&rev=553314&r1=553313&r2=553314
==============================================================================
--- spamassassin/branches/3.2/MANIFEST (original)
+++ spamassassin/branches/3.2/MANIFEST Wed Jul  4 12:49:58 2007
@@ -499,3 +499,4 @@
 t/root_spamd_tell_x_paranoid.t
 t/root_spamd_x.t
 t/root_spamd_x_paranoid.t
+t/spamc_H.t

Modified: spamassassin/branches/3.2/spamc/libspamc.c
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.2/spamc/libspamc.c?view=diff&rev=553314&r1=553313&r2=553314
==============================================================================
--- spamassassin/branches/3.2/spamc/libspamc.c (original)
+++ spamassassin/branches/3.2/spamc/libspamc.c Wed Jul  4 12:49:58 2007
@@ -1740,6 +1740,7 @@
     while (rnum-- > 0) {
         tmp = tp->hosts[0];
 
+        /* TODO: free using freeaddrinfo() */
         for (i = 1; i < tp->nhosts; i++)
             tp->hosts[i - 1] = tp->hosts[i];
 
@@ -1765,7 +1766,7 @@
 int transport_setup(struct transport *tp, int flags)
 {
 #ifdef SPAMC_HAS_ADDRINFO
-    struct addrinfo hints, *res; 
+    struct addrinfo hints, *res, *addrp; 
     char port[6];
 #else
     struct hostent *hp;
@@ -1878,6 +1879,13 @@
                 case EAI_FAIL: /*name server returned permanent error*/
                     errbits |= 2;
                     break;
+                default:
+                    /* should not happen, all errors are checked above */
+                    free(hostlist);
+                    return EX_OSERR;
+                }
+                goto nexthost; /* try next host in list */
+            }
 #else
             if ((hp = gethostbyname(hostname)) == NULL) {
                 int origerr = h_errno; /* take a copy before syslog() */
@@ -1892,7 +1900,6 @@
                 case NO_RECOVERY:
                     errbits |= 2;
                     break;
-#endif
                 default:
                     /* should not happen, all errors are checked above */
                     free(hostlist);
@@ -1900,16 +1907,18 @@
                 }
                 goto nexthost; /* try next host in list */
             }
+#endif
             
             /* If we have no hosts at all */
 #ifdef SPAMC_HAS_ADDRINFO
-            if(res == NULL) {
+            if(res == NULL)
 #else
             if (hp->h_addr_list[0] == NULL
              || hp->h_length != sizeof tp->hosts[0]
-             || hp->h_addrtype != AF_INET) {
+             || hp->h_addrtype != AF_INET)
                 /* no hosts/bad size/wrong family */
 #endif
+            {
                 errbits |= 1;
                 goto nexthost; /* try next host in list */
             }
@@ -1926,8 +1935,12 @@
                      TRANSPORT_MAX_HOSTS);
                break;
             }
-            tp->hosts[tp->nhosts] = res;
-            tp->nhosts++;
+            for (addrp = res; addrp != NULL; ) {
+                tp->hosts[tp->nhosts] = addrp;
+                addrp = addrp->ai_next;     /* before NULLing ai_next */
+                tp->hosts[tp->nhosts]->ai_next = NULL;
+                tp->nhosts++;
+            }
 #else
             for (addrp = hp->h_addr_list; *addrp; addrp++) {
                 if (tp->nhosts == TRANSPORT_MAX_HOSTS) {