Subject: | method "removeOption" corrupts the option_order index array |
Stephan,
I believe I've found a bug in the Net::DHCP::Packet.pm CPAN module. I'm
using version 0.65.
The removeOption method is not working. I've attempted to correct the
problem. Here's my suggested fix:
Show quoted text
> sub removeOption {
> my ($self,$key) = @_;
> if (exists($self->{options}->{$key})) {
> my $i;
> for ($i = 0; $i < @{$self->{options_order}}; $i++) {
> last if ($self->{options_order}->[$i] == $key); #added "== $key"
> }
> if ($i < @{$self->{options_order}}) {
> #delete ($self->{options_order}->[$i]);#commented out this line
> splice @{$self->{options_order}},$i,1;#added this line
> }
> delete ($self->{options}->{$key});
> }
> }
With the original code, the "last" statement was performed as soon as
the first non-zero $key was reached in the array reference
$self->{options_order}. I added the test operator "== $key".
Also, if the function "delete" is used on an index in the middle of an
array, the array element is not destroyed, it's just set to undefined. I
used the function splice instead, to be sure that the selected element
of the array was removed, and the array is shortened.
I'm running perl 5.8.7 on cygwin.
I hope this is helpful.
Nathan Scarlett