Subject: | is_unicast() incorrect for MAC addresses not beginning with '00' |
is_unicast() incorrectly returns false for MAC addresses where the first
octet isn't 0, caused by a precedence bug with '&' and '!'. The tests
didn't catch this because all the test MACs have a first octet of 00,
and the test just happens to pass when the first octet is 0.
I added explict parens to is_unicast() to fix the problem. I did the
same in is_multicast() for clarity, although strictly speaking it isn't
needed. I also added another test MAC for that situation. Patch is
attached.
Thanks for maintaining this module!
- Aaron
Subject: | NetAddr-MAC-unicast.patch |
diff -ur NetAddr-MAC-0.91/lib/NetAddr/MAC.pm NetAddr-MAC-0.91.new/lib/NetAddr/MAC.pm
--- NetAddr-MAC-0.91/lib/NetAddr/MAC.pm 2015-01-12 03:41:15.000000000 -0600
+++ NetAddr-MAC-0.91.new/lib/NetAddr/MAC.pm 2015-01-12 12:09:31.000000000 -0600
@@ -477,7 +477,7 @@
sub is_multicast {
my $self = shift;
- return $self->{mac}->[0] & 1 && ! is_broadcast($self);
+ return ($self->{mac}->[0] & 1) && ! is_broadcast($self);
}
@@ -601,7 +601,7 @@
sub is_unicast {
my $self = shift;
- return ! $self->{mac}->[0] & 1;
+ return ! ($self->{mac}->[0] & 1);
}
=head2 is_local
diff -ur NetAddr-MAC-0.91/t/131-utils-mac-properties.t NetAddr-MAC-0.91.new/t/131-utils-mac-properties.t
--- NetAddr-MAC-0.91/t/131-utils-mac-properties.t 2015-01-12 03:41:15.000000000 -0600
+++ NetAddr-MAC-0.91.new/t/131-utils-mac-properties.t 2015-01-12 15:07:30.000000000 -0600
@@ -81,12 +81,14 @@
# mac_is_vrrp mac_is_hsrp mac_is_hsrp2
my @unicasteui48macs = qw(
+ c82a14eeeeee
001122334455
003344aaccdd
00.11.22.33.44.aa
);
my @unicasteui64macs = qw(
+ c82a14eeeeeeeeee
0011223344556677
00aabbcc223344aa
00.bb.cc.aa.55.66