Subject: | Net-IP-Match-Bin does not match against /32 |
There is a bug matching against /32 "networks"
While matching the code walks the tree only for 32 levels but the match
field [2] for /32 is on level 33.
The patch contains fixes for Bin.xs and Perl.pm and modifies two tests to
validate.
Regards
Oliver Paukstadt
Subject: | fix-ugly-test.patch |
diff -Nur Net-IP-Match-Bin-0.05.orig/Bin.xs Net-IP-Match-Bin-0.05/Bin.xs
--- Net-IP-Match-Bin-0.05.orig/Bin.xs 2009-10-28 12:58:38.000000000 +0100
+++ Net-IP-Match-Bin-0.05/Bin.xs 2010-12-01 00:17:43.000000000 +0100
@@ -177,7 +177,7 @@
_dump(p, m_addr, 0);
m_addr = 0;
*/
- for (i=0; i<32; i++) {
+ for (i=0; i<=32; i++) {
if (p->code != NULL) {
/*printf("p->code: %s(%x)\n", p->code, p->code);*/
if (match != NULL && *match != NULL) {
diff -Nur Net-IP-Match-Bin-0.05.orig/blib/lib/Net/IP/Match/Bin/Perl.pm Net-IP-Match-Bin-0.05/blib/lib/Net/IP/Match/Bin/Perl.pm
--- Net-IP-Match-Bin-0.05.orig/blib/lib/Net/IP/Match/Bin/Perl.pm 2009-10-28 05:56:19.000000000 +0100
+++ Net-IP-Match-Bin-0.05/blib/lib/Net/IP/Match/Bin/Perl.pm 2010-12-01 00:16:38.000000000 +0100
@@ -90,7 +90,7 @@
my $tree = $self->{Tree};
my $addr = unpack 'N', pack 'C4', split /[.]/, $ip;
- for (my $i = 0; $i < 32; $i++) {
+ for (my $i = 0; $i <= 32; $i++) {
return $tree->[2] if defined $tree->[2];
my $bit = $addr & $BITS[$i] ? 1 : 0;
return undef unless defined $tree->[$bit];
diff -Nur Net-IP-Match-Bin-0.05.orig/t/2_match.t Net-IP-Match-Bin-0.05/t/2_match.t
--- Net-IP-Match-Bin-0.05.orig/t/2_match.t 2009-10-22 08:05:51.000000000 +0200
+++ Net-IP-Match-Bin-0.05/t/2_match.t 2010-11-30 23:55:46.000000000 +0100
@@ -25,6 +25,6 @@
$res = match_ip("172.16.5.1", "172.16.0.0/16", "192.168.1.0/24");
ok (defined($res) && ($res eq "172.16.0.0/16"), "match 5");
-$res = match_ip("192.16.5.1", "172.16.0.0/16", "192.168.1.0/24");
-ok (!defined($res), "match 6");
+$res = match_ip("172.16.5.1", "172.16.5.1/32", "192.168.1.0/24");
+ok (defined($res), "match 6");
diff -Nur Net-IP-Match-Bin-0.05.orig/t/3_perl.t Net-IP-Match-Bin-0.05/t/3_perl.t
--- Net-IP-Match-Bin-0.05.orig/t/3_perl.t 2009-10-28 05:53:39.000000000 +0100
+++ Net-IP-Match-Bin-0.05/t/3_perl.t 2010-12-01 00:05:39.000000000 +0100
@@ -26,6 +26,5 @@
$res = match_ip("172.16.5.1", "172.16.0.0/16", "192.168.1.0/24");
ok (defined($res) && ($res eq "172.16.0.0/16"), "match 5 res=$res");
-$res = match_ip("192.16.5.1", "172.16.0.0/16", "192.168.1.0/24");
-ok (!defined($res), "match 6");
-
+$res = match_ip("172.16.5.1", "172.16.5.1/32", "192.168.1.0/24");
+ok (defined($res), "match 6");