patch-lib_Mail_SpamAssassin_DnsResolver_pm 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. $OpenBSD: patch-lib_Mail_SpamAssassin_DnsResolver_pm,v 1.4 2016/03/04 00:05:35 sthen Exp $
  2. --- lib/Mail/SpamAssassin/DnsResolver.pm.orig Tue Apr 28 20:56:49 2015
  3. +++ lib/Mail/SpamAssassin/DnsResolver.pm Thu Mar 3 23:59:55 2016
  4. @@ -592,6 +592,9 @@ sub new_dns_packet {
  5. };
  6. if ($packet) {
  7. + # RD flag needs to be set explicitly since Net::DNS 1.01, Bug 7223
  8. + $packet->header->rd(1);
  9. +
  10. # my $udp_payload_size = $self->{res}->udppacketsize;
  11. my $udp_payload_size = $self->{conf}->{dns_options}->{edns};
  12. if ($udp_payload_size && $udp_payload_size > 512) {
  13. @@ -722,6 +725,37 @@ sub bgsend {
  14. ###########################################################################
  15. +=item $id = $res->bgread()
  16. +
  17. +Similar to C<Net::DNS::Resolver::bgread>. Reads a DNS packet from
  18. +a supplied socket, decodes it, and returns a Net::DNS::Packet object
  19. +if successful. Dies on error.
  20. +
  21. +=cut
  22. +
  23. +sub bgread() {
  24. + my ($self) = @_;
  25. + my $sock = $self->{sock};
  26. + my $packetsize = $self->{res}->udppacketsize;
  27. + $packetsize = 512 if $packetsize < 512; # just in case
  28. + my $data = '';
  29. + my $peeraddr = $sock->recv($data, $packetsize+256); # with some size margin for troubleshooting
  30. + defined $peeraddr or die "bgread: recv() failed: $!";
  31. + my $peerhost = $sock->peerhost;
  32. + $data ne '' or die "bgread: received empty packet from $peerhost";
  33. + dbg("dns: bgread: received %d bytes from %s", length($data), $peerhost);
  34. + my($answerpkt, $decoded_length) = Net::DNS::Packet->new(\$data);
  35. + $answerpkt or die "bgread: decoding DNS packet failed: $@";
  36. + $answerpkt->answerfrom($peerhost);
  37. + if ($decoded_length ne length($data)) {
  38. + warn sprintf("bgread: received a %d bytes packet from %s, decoded %d bytes\n",
  39. + length($data), $peerhost, $decoded_length);
  40. + }
  41. + return $answerpkt;
  42. +}
  43. +
  44. +###########################################################################
  45. +
  46. =item $nfound = $res->poll_responses()
  47. See if there are any C<bgsend> reply packets ready, and return
  48. @@ -769,13 +803,25 @@ sub poll_responses {
  49. $timeout = 0; # next time around collect whatever is available, then exit
  50. last if $nfound == 0;
  51. - my $packet = $self->{res}->bgread($self->{sock});
  52. + my $packet;
  53. + eval {
  54. + $packet = $self->bgread();
  55. + } or do {
  56. + undef $packet;
  57. + my $eval_stat = $@ ne '' ? $@ : "errno=$!"; chomp $eval_stat;
  58. + # resignal if alarm went off
  59. + die $eval_stat if $eval_stat =~ /__alarm__ignore__\(.*\)/s;
  60. + info("dns: bad dns reply: %s", $eval_stat);
  61. + };
  62. +# Bug 7265, use our own bgread()
  63. +# my $packet = $self->{res}->bgread($self->{sock});
  64. +
  65. if (!$packet) {
  66. - my $dns_err = $self->{res}->errorstring;
  67. - # resignal if alarm went off
  68. - die "dns (3) $dns_err\n" if $dns_err =~ /__alarm__ignore__\(.*\)/s;
  69. - info("dns: bad dns reply: $dns_err");
  70. + # error already reported above
  71. +# my $dns_err = $self->{res}->errorstring;
  72. +# die "dns (3) $dns_err\n" if $dns_err =~ /__alarm__ignore__\(.*\)/s;
  73. +# info("dns: bad dns reply: $dns_err");
  74. } else {
  75. my $header = $packet->header;
  76. if (!$header) {