Skip Menu |

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

Report information
The Basics
Id: 92487
Status: new
Priority: 0/
Queue: Net-Subnet

People
Owner: Nobody in particular
Requestors: galvao.m [...] gmail.com
Cc:
AdminCc:

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



Subject: MIssing "/" in any of the subnets makes subnet_matcher's result to always answer true
Net-Subnet-1.03 perl v5.10.1 I can see between the caveats that there is no argument validation, but I would still suggest to change the "default" behaviour when a mask/length is not provided. Some people might think the method will default to a /32. * Code to reproduce the bug The following will print "matched" use warnings; use Net::Subnet; my $matcher = subnet_matcher qw( 1.2.3.4 ); print $matcher->('5.6.7.8') ? 'matched' : 'unmatched', "\n"; * Possible code changes When a / is not in input, either throw an exception: sub subnet_matcher { @_ > 1 and goto &multi_matcher; my ($net, $mask) = split m[/], shift; die "Invalid mask/length" if !defined($mask); return $net =~ /:/ ? ipv6_matcher($net, $mask) : ipv4_matcher($net, $mask); } or use 32/64 for the length: sub subnet_matcher { @_ > 1 and goto &multi_matcher; my ($net, $mask) = split m[/], shift; return $net =~ /:/ ? ipv6_matcher($net, $mask // 64) : ipv4_matcher($net, $mask // 32); } I didn't consider cases with the / followed by nothing/spaces, as it would make the code probably too complex.