Skip Menu |
 

This queue is for tickets about the Net-Whois-IANA CPAN distribution.

Report information
The Basics
Id: 82174
Status: deleted
Priority: 0/
Queue: Net-Whois-IANA

People
Owner: cpan [...] parparov.com
Requestors: KENTNL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.40
Fixed in: (no value)



Subject: Hash Randomization causes random test failure

It would appear with 90-misc.t , test 2 ,  https://metacpan.org/source/ROMM/Net-Whois-IANA-0.40/t/90-misc.t#L11   , randomly fails because "->is_mine" randomly returns true.

 

Upon further inspection, this seems to be because the value "->cidr" randomly switches between /8  and /21

 

And the result is that on my system with perl 5.17 , the following code snippet produces consistent output

 

https://gist.github.com/4359102#file-test-pm

use strict;
use warnings;
 
use Data::Dumper qw( Dumper );
 
my ( @hashes ) = qw( 0xda21c880 0xcb670160 );
 
sub in_ps {
my ( $it, $hash ) = @_;
$ENV{PERL_HASH_SEED} = $hash;
system($^X,'-E',<<"EOF");
use Net::Whois::IANA;
use Data::Dumper qw( Dumper );
\$Data::Dumper::Terse=1;
\$Data::Dumper::Indent=0;
my \$instance = Net::Whois::IANA->new();
\$instance->whois_query( -ip => q{193.0.0.135});
printf "%s %s %s mine=%s\n", $it, "$hash", Dumper( \$instance->cidr() ), \$instance->is_mine(q{193.0.8.1});
EOF
 
}
 
 
for my $i ( 0 .. 5 ){
for my $hash ( @hashes ) {
in_ps($i,$hash);
}
}

 

OUTPUT:---

 

PERL5OPT="-Ilib" perl t/91-hash-random.t
0 0xda21c880 ['193.0.0.0/21'] mine=0
0 0xcb670160 ['193.0.0.0/8'] mine=1
1 0xda21c880 ['193.0.0.0/21'] mine=0
1 0xcb670160 ['193.0.0.0/8'] mine=1
2 0xda21c880 ['193.0.0.0/21'] mine=0
2 0xcb670160 ['193.0.0.0/8'] mine=1
3 0xda21c880 ['193.0.0.0/21'] mine=0
3 0xcb670160 ['193.0.0.0/8'] mine=1
4 0xda21c880 ['193.0.0.0/21'] mine=0
4 0xcb670160 ['193.0.0.0/8'] mine=1
5 0xda21c880 ['193.0.0.0/21'] mine=0
5 0xcb670160 ['193.0.0.0/8'] mine=1
On 2012-12-23 03:37:32, KENTNL wrote:
Show quoted text
> It would appear with 90-misc.t , test 2 ,
> https://metacpan.org/source/ROMM/Net-Whois-IANA-0.40/t/90-misc.t#L11 ,
> randomly
> fails because "->is_mine" randomly returns true.
>

Looks like the bad code is in https://metacpan.org/source/ROMM/Net-Whois-IANA-0.40/lib/Net/Whois/IANA.pm#L226

 

Because

    my @source_names = keys %{$self->{source}};

is not sorted, the actual order of the sort is completely random, and in the example, it switches between RIPE and ARIN , and RIPE returns /21 and ARIN returns /8

So the solution is either do
 

    my @source_names = sort keys %{$self->{source}};


which will result in the query order being: afrinc. apnic, arin , and then get a result from arin, and return a /8 CIDR 

 

This however will make the "is_mine" test consistently fail. 



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.