Branch Coverage

blib/lib/Mail/SpamAssassin/DnsResolver.pm
Criterion Covered Total %
branch 108 278 38.8


line true false branch
58 40 0 if (eval { do { require IO::Socket::IP } }) { }
0 0 elsif (eval { do { require IO::Socket::INET6 } }) { }
0 0 elsif (eval { do { require IO::Socket::INET } }) { }
97 0 91 if ($self->{'res'})
104 0 91 if (not $force_ipv4 and $io_socket_module_name eq 'IO::Socket::INET')
106 0 0 if $force_ipv6
109 91 0 unless ($force_ipv4)
112 91 0 if ($io_socket_module_name)
115 0 0 unless $sock6->close
0 91 if ($sock6)
117 91 0 unless (eval { do { my $sock6; if ($io_socket_module_name) { $sock6 = $io_socket_module_name->new('LocalAddr', '::', 'Proto', 'udp'); } ; if ($sock6) { warn "error closing socket: $!" unless $sock6->close; } ; $sock6 } })
120 0 91 if $force_ipv6
131 91 0 if ($res)
150 91 0 if ($edns and $edns > 512)
160 180 0 /^\[(.*)\]:(\d+)\z/ ? :
165 0 91 unless (eval { do { require Net::DNS; my $res = $self->{'res'} = 'Net::DNS::Resolver'->new('force_v4', $force_ipv4); if ($res) { $self->{'no_resolver'} = 0; $self->{'force_ipv4'} = $force_ipv4; $self->{'force_ipv6'} = $force_ipv6; $self->{'retry'} = 1; $self->{'retrans'} = 3; $res->retry(1); $res->retrans(0); $res->dnsrch(0); $res->defnames(0); $res->tcp_timeout(3); $res->udp_timeout(3); $res->persistent_tcp(0); $res->persistent_udp(0); my $edns = $self->{'conf'}{'dns_options'}{'edns'}; if ($edns and $edns > 512) { $res->udppacketsize($edns); dbg('dns: EDNS, UDP payload size %d', $edns); } ; my(@ns_addr_port) = $self->available_nameservers; local($1, $2); @ns_addr_port = map((/^\[(.*)\]:(\d+)\z/ ? $1 : $_), @ns_addr_port); dbg('dns: nameservers set to %s', join(', ', @ns_addr_port)); $res->nameservers(@ns_addr_port); } ; 1 } })
166 0 0 $@ ne '' ? :
174 0 0 $self->{'force_ipv6'} ? :
91 0 $self->{'force_ipv4'} ? :
176 0 91 $self->{'no_resolver'} ? :
177 91 0 if (not $self->{'no_resolver'} and defined $Net::DNS::VERSION)
207 1 89 if ($self->{'conf'}{'dns_servers'}) { }
89 0 elsif ($res) { }
212 89 0 $res->UNIVERSAL::can('nameservers') ? :
213 0 89 $res->UNIVERSAL::can('port') ? :
230 0 114 if (@_) { }
90 24 elsif (not $self->{'available_dns_servers'}) { }
238 114 0 if ($self->{'force_ipv4'} or $self->{'force_ipv6'})
244 0 203 unless /^ \[ (.*) \] : (\d+) \z/sx
246 203 0 if ($addr =~ /^$ip4_re\z/o) { }
0 0 elsif ($addr =~ /:.*:/) { }
247 203 0 unless $self->{'force_ipv6'}
249 0 0 unless $self->{'force_ipv4'}
254 0 114 if (@filtered_addr_port < @{$self->{'available_dns_servers'};})
261 0 114 unless @{$self->{'available_dns_servers'};}
267 0 0 if ($lport >= 0 and $lport <= 65535)
269 0 0 unless (defined $conf->{'dns_available_portscount'})
272 0 0 if (vec $conf->{'dns_available_ports_bitset'}, $lport, 1)
289 1 1 unless (defined $available_portscount)
291 1 0 unless (defined $ports_bitset)
306 4 252 if ($b eq $all_zeroes) { }
252 0 elsif ($b eq $all_ones) { }
315 1 0 if ($available_portscount) { }
325 2 0 if ($available_portscount > 0)
333 2 63 if ($cnt > $n) { }
337 320 0 if (vec $ports_bitset, $ind, 1)
338 2 318 if ($n <= 0) { }
356 0 2 $self->{'no_resolver'} ? :
357 0 2 if $self->{'no_resolver'}
359 0 2 unless $io_socket_module_name
362 0 2 if ($self->{'sock'})
364 0 0 unless $self->{'sock'}->close
374 2 0 if $ns_addr_port[0] =~ /^\[(.*)\]:(\d+)\z/
383 2 0 if ($self->{'force_ipv4'}) { }
0 0 elsif ($self->{'force_ipv6'}) { }
0 0 elsif ($ns_addr =~ /^$ip4_re\z/o) { }
0 0 elsif ($ns_addr =~ /:.*:/) { }
401 0 2 unless (defined $lport)
405 0 2 if ($attempts + 1 > 50)
422 2 0 if $sock
425 0 0 $io_socket_module_name eq 'IO::Socket::IP' ? :
427 0 0 if ($! == 98 or $! == 13) { }
430 0 0 if ($self->{'conf'}{'dns_available_portscount'} > 100)
438 0 2 unless ($sock)
445 0 2 unless $bufsiz = $sock->sockopt(8)
447 2 0 if ($bufsiz >= 32768) { }
451 0 0 unless $sock->sockopt(8, 32768)
453 0 0 unless $newbufsiz = $sock->sockopt(8)
459 0 2 unless (eval { do { my($bufsiz, $newbufsiz); die "cannot get a resolver socket rx buffer size: $!" unless $bufsiz = $sock->sockopt(8); if ($bufsiz >= 32768) { dbg('dns: resolver socket rx buffer size is %d bytes, local port %d', $bufsiz, $lport); } else { die "cannot set a resolver socket rx buffer size: $!" unless $sock->sockopt(8, 32768); die "cannot get a resolver socket rx buffer size: $!" unless $newbufsiz = $sock->sockopt(8); dbg('dns: resolver socket rx buffer size changed from %d to %d bytes, local port %d', $bufsiz, $newbufsiz, $lport); } ; 1 } })
460 0 0 $@ ne '' ? :
475 2 19 if not $self->{'sock'}
515 0 0 if (chr($ic) =~ /^[A-Za-z]\z/)
516 0 0 if ($have_rnd_bits < 1)
520 0 0 if $rnd & 1
533 0 21 if $self->{'no_resolver'}
536 0 21 if (not defined $type or $type eq 'PTR')
538 0 0 if ($domain =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/)
543 0 21 unless defined $type
544 21 0 unless defined $class
549 0 21 if (utf8::is_utf8($domain))
554 0 21 if (length $domain > 255) { }
0 21 elsif (not $domain =~ /^ (?: [^.]{1,63} \. )+ \z/sx) { }
557 0 0 if (not $domain =~ /^ (?: [^.]+ \. )+ \z/sx) { }
564 0 21 if ($self->{'conf'}{'dns_options'}{'dns0x20'}) { }
574 0 0 $1 eq '\\' ? :
582 0 21 unless (eval { do { if (utf8::is_utf8($domain)) { dbg('dns: new_dns_packet: domain is utf8 flagged: %s', $domain); } ; $domain =~ s/\.*\z/./s; if (length $domain > 255) { die "domain name longer than 255 bytes\n"; } elsif (not $domain =~ /^ (?: [^.]{1,63} \. )+ \z/sx) { if (not $domain =~ /^ (?: [^.]+ \. )+ \z/sx) { die "a domain name contains a null label\n"; } else { die "a label in a domain name is longer than 63 bytes\n"; } ; } ; if ($self->{'conf'}{'dns_options'}{'dns0x20'}) { $domain = dnsext_dns0x20($domain); } else { $domain =~ tr/A-Z/a-z/; } ; $domain =~ s/ ( [\000-\037\177-\377\\] ) /$1 eq '\\' ? "\\$1" : sprintf('\\%03d', ord $1);/egsx; $packet = 'Net::DNS::Packet'->new($domain, $type, $class); 1 } })
585 0 0 $@ ne '' ? :
587 0 0 if $eval_stat =~ /__alarm__ignore__\(.*\)/s
592 21 0 if ($packet)
598 21 0 if ($udp_payload_size and $udp_payload_size > 512)
600 21 0 if ($packet->UNIVERSAL::can('edns')) { }
624 0 42 unless @questions <= 1
627 42 0 if ($questions[0]) { }
639 42 0 unless $self->{'conf'}{'dns_options'}{'dns0x20'}
685 0 21 if $self->{'no_resolver'}
690 0 21 unless $pkt
701 21 0 if ($self->{'sock'} and defined $self->{'sock'}->send($pkt->data, 0)) { }
704 0 0 !$self->{'sock'} ? :
707 0 0 if ($attempts >= $n_servers)
717 0 21 unless $ok
738 0 21 if $packetsize < 512
741 0 21 unless defined $peeraddr
743 0 21 unless $data ne ''
746 0 21 unless $answerpkt
748 0 21 if (defined $decoded_length and $decoded_length ne '' and $decoded_length != length $data)
766 0 11 if $self->{'no_resolver'}
767 0 11 unless $self->{'sock'}
777 8 24 if (not defined $timeout or $timeout > 0)
782 0 32 unless (eval { do { my $timer; if (not defined $timeout or $timeout > 0) { $timer = $self->{'main'}->time_method('poll_dns_idle'); } ; $! = 0; ($nfound, $timeleft) = select($rout = $rin, undef, undef, $timeout); 1 } })
783 0 0 $@ ne '' ? :
785 0 32 if (defined $eval_stat) { }
0 32 elsif (not defined $nfound or $nfound < 0) { }
11 21 elsif (not $nfound) { }
787 0 0 if $eval_stat =~ /__alarm__ignore__\(.*\)/s
791 0 0 if ($!) { }
795 0 11 if (not defined $timeout) { }
0 11 elsif ($timeout > 0) { }
802 0 21 if $nfound == 0
809 0 21 unless (eval { do { $packet = $self->bgread } })
811 0 0 $@ ne '' ? :
813 0 0 if $eval_stat =~ /__alarm__ignore__\(.*\)/s
817 0 21 if (not $packet) { }
824 0 21 if (not $header) { }
831 10 11 if ($rcode eq 'NOERROR') { }
835 0 10 if ($header->tc)
837 0 0 $edns == 512 ? :
853 21 0 if ($cb) { }
857 0 0 if ($rcode eq 'REFUSED' or $id =~ m[^\d+/NO_QUESTION_IN_PACKET\z]) { }
862 0 0 $packet ? :
866 0 0 if ($id =~ m[^(\d+)/])
870 0 0 if (not @matches) { }
915 0 8 if $self->{'no_resolver'}
934 0 8 if $timeout < 1
941 0 8 unless defined $id
947 0 8 if ($now >= $deadline)
971 0 0 if $self->{'send_timed_out'}
985 2 51 if ($self->{'sock'})
987 0 2 unless $self->{'sock'}->close
1015 0 2 if (not defined $fno) { }