View | Details | Raw Unified | Return to bug 204682 | Differences between
and this patch

Collapse All | Expand All

(-)lib/Mail/SpamAssassin/DnsResolver.pm (-5 / +48 lines)
Lines 725-730 Link Here
725
725
726
###########################################################################
726
###########################################################################
727
727
728
=item $id = $res->bgread()
729
730
Similar to C<Net::DNS::Resolver::bgread>.  Reads a DNS packet from
731
a supplied socket, decodes it, and returns a Net::DNS::Packet object
732
if successful.  Dies on error.
733
734
=cut
735
736
sub bgread() {
737
  my ($self) = @_;
738
  my $sock = $self->{sock};
739
  my $packetsize = $self->{res}->udppacketsize;
740
  $packetsize = 512  if $packetsize < 512;  # just in case
741
  my $data = '';
742
  my $peeraddr = $sock->recv($data, $packetsize+256);  # with some size margin for troubleshooting
743
  defined $peeraddr or die "bgread: recv() failed: $!";
744
  my $peerhost = $sock->peerhost;
745
  $data ne '' or die "bgread: received empty packet from $peerhost";
746
  dbg("dns: bgread: received %d bytes from %s", length($data), $peerhost);
747
  my($answerpkt, $decoded_length) = Net::DNS::Packet->new(\$data);
748
  $answerpkt or die "bgread: decoding DNS packet failed: $@";
749
  $answerpkt->answerfrom($peerhost);
750
  if ($decoded_length ne length($data)) {
751
    warn sprintf("bgread: received a %d bytes packet from %s, decoded %d bytes\n",
752
                 length($data), $peerhost, $decoded_length);
753
  }
754
  return $answerpkt;
755
}
756
757
###########################################################################
758
728
=item $nfound = $res->poll_responses()
759
=item $nfound = $res->poll_responses()
729
760
730
See if there are any C<bgsend> reply packets ready, and return
761
See if there are any C<bgsend> reply packets ready, and return
Lines 772-784 Link Here
772
    $timeout = 0;  # next time around collect whatever is available, then exit
803
    $timeout = 0;  # next time around collect whatever is available, then exit
773
    last  if $nfound == 0;
804
    last  if $nfound == 0;
774
805
775
    my $packet = $self->{res}->bgread($self->{sock});
806
    my $packet;
807
    eval {
808
      $packet = $self->bgread();
809
    } or do {
810
      undef $packet;
811
      my $eval_stat = $@ ne '' ? $@ : "errno=$!";  chomp $eval_stat;
812
      # resignal if alarm went off
813
      die $eval_stat  if $eval_stat =~ /__alarm__ignore__\(.*\)/s;
814
      info("dns: bad dns reply: %s", $eval_stat);
815
    };
776
816
817
#   Bug 7265, use our own bgread()
818
#   my $packet = $self->{res}->bgread($self->{sock});
819
777
    if (!$packet) {
820
    if (!$packet) {
778
      my $dns_err = $self->{res}->errorstring;
821
      # error already reported above
779
      # resignal if alarm went off
822
#     my $dns_err = $self->{res}->errorstring;
780
      die "dns (3) $dns_err\n"  if $dns_err =~ /__alarm__ignore__\(.*\)/s;
823
#     die "dns (3) $dns_err\n"  if $dns_err =~ /__alarm__ignore__\(.*\)/s;
781
      info("dns: bad dns reply: $dns_err");
824
#     info("dns: bad dns reply: $dns_err");
782
    } else {
825
    } else {
783
      my $header = $packet->header;
826
      my $header = $packet->header;
784
      if (!$header) {
827
      if (!$header) {

Return to bug 204682