diff --git a/Changes b/Changes index 72e174a..d8e1e19 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,16 @@ Revision history for Perl extension NetAddr::IP +4.061 Tue May 8 16:24:03 PDT 2012 + fixed bug in Lite v1.44 that returned + $ip->num() = 2^128 for 0.0.0.0/0 + Thanks to Sebastian for spotting it. + +4.060 Fri Apr 6 16:00:02 PDT 2012 + In Lite.pm v1.43, + fix bug #75976, change in behavior introduced in v4.050 + where an empty string supplied to "new" previously returned + 'undef' and now returns 'default' for ipV4 or ipV6 + 4.059 Wed Mar 7 12:50:04 PST 2012 add is_rfc1918 to Lite.pm v1.42 diff --git a/IP.pm b/IP.pm index e57d786..e35cef6 100644 --- a/IP.pm +++ b/IP.pm @@ -4,7 +4,7 @@ use strict; #use diagnostics; -use NetAddr::IP::Lite 1.42 qw(Zero Zeros Ones V4mask V4net); +use NetAddr::IP::Lite 1.44 qw(Zero Zeros Ones V4mask V4net); use NetAddr::IP::Util 1.46 qw( sub128 inet_aton @@ -35,7 +35,7 @@ @ISA = qw(Exporter NetAddr::IP::Lite); -$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.59 $ =~ /\d+/g) }; +$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.61 $ =~ /\d+/g) }; =pod @@ -566,6 +566,8 @@ If called with no arguments, 'default' is assumed. +If called with an empty string as the argument, returns 'undef' + C<$addr> can be any of the following and possibly more... n.n @@ -600,6 +602,8 @@ If called with no arguments, 'default' is assumed. +If called with an empty string as the argument, returns 'undef' + =item C<-Ebroadcast()> Returns a new object referring to the broadcast address of a given diff --git a/Lite/Changes b/Lite/Changes index f09a25f..01ca42b 100644 --- a/Lite/Changes +++ b/Lite/Changes @@ -1,5 +1,14 @@ Revision history for Perl extension NetAddr::IP::Lite +1.44 Tue May 8 16:24:03 PDT 2012 + fixed bug that return $ip->num() = 2^128 for 0.0.0.0/0 + Thanks to Sebastian for spotting it. + +1.43 Fri Apr 6 13:19:48 PDT 2012 + fix bug #75976, change in behavior introduced in v4.050 + where an empty string supplied to "new" previously returned + 'undef' and now returns 'default' for ipV4 or ipV6 + 1.42 Wed Mar 7 12:50:04 PST 2012 add "is_rfc1918" and tests diff --git a/Lite/Lite.pm b/Lite/Lite.pm index 7a5dced..b6d29b2 100644 --- a/Lite/Lite.pm +++ b/Lite/Lite.pm @@ -32,7 +32,7 @@ use vars qw(@ISA @EXPORT_OK $VERSION $Accept_Binary_IP $Old_nth $AUTOLOAD *Zero); -$VERSION = do { my @r = (q$Revision: 1.42 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$VERSION = do { my @r = (q$Revision: 1.44 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; require Exporter; @@ -574,6 +574,8 @@ If called with no arguments, 'default' is assumed. +If called with an empty string as the argument, returns 'undef' + C<$addr> can be any of the following and possibly more... n.n @@ -612,6 +614,8 @@ If called with no arguments, 'default' is assumed. +If called with and empty string as the argument, 'undef' is returned; + =cut my $lbmask = inet_aton('255.0.0.0'); @@ -729,6 +733,9 @@ my $class = ref $proto || $proto || __PACKAGE__; my $ip = shift; +# fix for bug #75976 + return undef if defined $ip && $ip eq ''; + $ip = 'default' unless defined $ip; $ip = _retMBIstring($ip) # treat as big bcd string if ref $ip && ref $ip eq 'Math::BigInt'; # can /CIDR notation @@ -1500,6 +1507,7 @@ return 1 unless hasbits($net); # ipV4/32 or ipV6/128 $net = $net ^ Ones; return 2 unless hasbits($net); # ipV4/31 or ipV6/127 + $net &= $_v4net unless $_[0]->{isv6}; return bin2bcd($net); } } diff --git a/Lite/MANIFEST b/Lite/MANIFEST index af981dd..8ee751c 100644 --- a/Lite/MANIFEST +++ b/Lite/MANIFEST @@ -14,6 +14,7 @@ t/bits.t t/broadcast.t t/bug62521.t +t/bug75976.t t/cidr.t t/constants.t t/contains.t diff --git a/Lite/README b/Lite/README index 21845a2..dd935a1 100644 --- a/Lite/README +++ b/Lite/README @@ -252,6 +252,8 @@ If called with no arguments, 'default' is assumed. + If called with an empty string as the argument, returns 'undef' + "$addr" can be any of the following and possibly more... n.n @@ -289,6 +291,9 @@ If called with no arguments, 'default' is assumed. + If called with and empty string as the argument, 'undef' is + returned; + "->broadcast()" Returns a new object referring to the broadcast address of a given subnet. The broadcast address has all ones in all the bit positions diff --git a/Lite/t/bug75976.t b/Lite/t/bug75976.t new file mode 100644 index 0000000..9cfe498 --- /dev/null +++ b/Lite/t/bug75976.t @@ -0,0 +1,41 @@ + +BEGIN { $| = 1; print "1..7\n"; } +END {print "not ok 1\n" unless $loaded;} + +$loaded = 1; +print "ok 1\n"; + +#use diagnostics; +use NetAddr::IP::Lite; + +$| = 1; + +my $test = 2; + +sub ok() { + print 'ok ',$test++,"\n"; +} + +my $ud = undef; +my @bugtest = ( + 0 => '0.0.0.0/32', '0:0:0:0:0:0:0:0/128', + $ud => '0.0.0.0/0', '0:0:0:0:0:0:0:0/0', + "" => 'undef', 'undef', +); + + +for (my $i=0;$i <= $#bugtest;$i+=3) { + my $ip6 = sprintf("%s", NetAddr::IP::Lite->new6($bugtest[$i]) || 'undef'); + my $ip = sprintf ("%s", NetAddr::IP::Lite->new($bugtest[$i]) || 'undef'); + my $expip = $bugtest[$i+1]; + my $expip6 = $bugtest[$i+2]; + + print "got: $ip\nexp: $expip\nnot " + unless $ip eq $expip; + &ok; + + print "got: $ip6\nexp: $expip6\nnot " + unless $ip6 eq $expip6; + &ok; + +} diff --git a/Lite/t/v4-num.t b/Lite/t/v4-num.t index 8d74bb6..8e766b6 100644 --- a/Lite/t/v4-num.t +++ b/Lite/t/v4-num.t @@ -6,6 +6,7 @@ '10.0.0.16' => [ 24, 255 ], '10.128.0.1' => [ 8, 2 ** 24 - 1 ], '10.0.0.5' => [ 30, 3 ], + '0.0.0.0' => [ 0, 2 ** 32 -1 ], }; my $new = 1; # flag for old vs new numeric returns diff --git a/MANIFEST b/MANIFEST index ba10a4c..a069904 100644 --- a/MANIFEST +++ b/MANIFEST @@ -52,6 +52,7 @@ Lite/t/bits.t Lite/t/broadcast.t Lite/t/bug62521.t +Lite/t/bug75976.t Lite/t/cidr.t Lite/t/constants.t Lite/t/contains.t diff --git a/META.yml b/META.yml index ec28ad6..8d42036 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: NetAddr-IP -version: 4.059 +version: 4.061 abstract: Manages IPv4 and IPv6 addresses and subnets license: ~ author: diff --git a/Makefile.PL b/Makefile.PL index cb0d83c..ab92c33 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,7 +19,7 @@ # YOUR VERSION OF PERL = $pv HAS SERIOUS BUGS # # # # Early versions of perl 5.8.x contain bugs that cause certain # -# \@_ operations to fail. See perl bug [ 23429] # +# \@_ operations to fail. See perl bug [ 23429] # # Please upgrade to at least perl 5.8.6 # # # #################################################################