This is the corrected patch that ensures that IDs are not colliding by
including the host name in an SHA1 hash with the 16 bit ID counter.

It is written a bit crudely, but if Theo or someone else who is seeing the
problem would try this in a mass test it would demonstrate whether the
problem has anything to do with this:

 -- sidney

Index: lib/Mail/SpamAssassin/Dns.pm
===================================================================
--- lib/Mail/SpamAssassin/Dns.pm        (revision 164570)
+++ lib/Mail/SpamAssassin/Dns.pm        (working copy)
@@ -22,6 +22,7 @@
 use Mail::SpamAssassin::Conf;
 use Mail::SpamAssassin::PerMsgStatus;
 use Mail::SpamAssassin::Constants qw(:ip);
+use Digest::SHA1 qw(sha1_base64);
 use File::Spec;
 use IO::Socket;
 use IPC::Open2;
@@ -145,7 +146,10 @@

   return $self->{resolver}->bgsend($host, $type, undef, sub {
           my $pkt = shift;
-          $self->{dnsfinished}->{$pkt->header->id} = $pkt;
+          my $h = $host;
+          $h =~ s/\.$//;
+          my $id = substr(sha1_base64($h . $pkt->header->id), -8);
+          $self->{dnsfinished}->{$id} = $pkt;
         });
 }

Index: lib/Mail/SpamAssassin/DnsResolver.pm
===================================================================
--- lib/Mail/SpamAssassin/DnsResolver.pm        (revision 164570)
+++ lib/Mail/SpamAssassin/DnsResolver.pm        (working copy)
@@ -45,7 +45,7 @@
 use Mail::SpamAssassin::Logger;

 use IO::Socket::INET;
-
+use Digest::SHA1 qw(sha1_base64);
 our @ISA = qw();

 # a counter value to use for DNS ID numbers in new_dns_packet().
@@ -243,8 +243,8 @@
   return if $self->{no_resolver};

   my $pkt = $self->new_dns_packet($host, $type, $class);
-
-  my $id = $pkt->header->id;
+  $host =~ s/\.$//;
+  my $id = substr(sha1_base64($host . $pkt->header->id), -8);
   my $data = $pkt->data;
   my $dest = $self->{dest};
   if (!$self->{sock}->send ($pkt->data, 0, $self->{dest})) {
@@ -291,8 +291,11 @@
       defined $packet->answer)
   {
     my $header = $packet->header;
-    my $id = $header->id;
-
+    my @questions = $packet->question;
+    my $ques = $questions[0];
+    my $host = $ques->qname;
+    my $nid = $header->id;
+    my $id = substr(sha1_base64($host . $nid), -8);
     # dbg("dns: reply id=$id");

     my $cb = delete $self->{id_to_callback}->{$id};

Reply via email to