Skip Menu |

This queue is for tickets about the NetAddr-MAC CPAN distribution.

Report information
The Basics
Id: 101508
Status: resolved
Priority: 0/
Queue: NetAddr-MAC

People
Owner: Nobody in particular
Requestors: vitahall [...] cpan.org
Cc:
AdminCc:

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



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
many thanks, especially for updating the test cases! 0.92 released to cpan including your fixes On Mon Jan 12 16:49:55 2015, VITAHALL wrote: Show quoted text
> 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