Skip Menu |

This queue is for tickets about the POE-Component-SNMP CPAN distribution.

Report information
The Basics
Id: 47751
Status: new
Priority: 0/
Queue: POE-Component-SNMP

People
Owner: Nobody in particular
Requestors: acferen [...] yahoo.com
Cc:
AdminCc:

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



Subject: Use of uninitialized value in _arg_scan
The actual error is Use of uninitialized value in pattern match (m//) at POE/Component/SNMP.pm line 336. The problem occurs because _arg_scan splices out the key/value pair once it is located, but then continues iterating over the @arg array using the indexes from before the splice. There is also the subtle issue that all the values are tested as possible keys. Assuming that values will never match the key regexp and that no key occurs more than once the problem can be fixed by calling 'last' after the splice or iterating over the list in reverse. patch (making no assumtions) attached.
Subject: arg_scan.patch
Index: lib/POE/Component/SNMP.pm =================================================================== --- lib/POE/Component/SNMP.pm (revision 4341) +++ lib/POE/Component/SNMP.pm (working copy) @@ -2,7 +2,7 @@ use strict; -our $VERSION = '1.1001_1'; +our $VERSION = '1.1001_2'; package POE::Net::SNMP; @@ -329,19 +329,19 @@ # key/value pair. sub _arg_scan { my ($key, @arg) = @_; - - my $value; + my ($value, $k_idx, $v_idx, @ret_arg); # scan the @arg for any keys that are callback args. - for (0..$#arg) { - if ($arg[$_] =~ /^-?$key$/i) { - $value = $arg[$_ + 1]; - - # splice out the key and value from @arg: - splice @arg, $_, 2; - } + for $k_idx ( map { $_*2 } (0..(@arg/2-1)) ) { + $v_idx = ($k_idx+1); + if ($arg[$k_idx] =~ m/^-?$key$/i) { + $value = $arg[$v_idx]; + } else { + # we only return args that didn't match our scan. + push @ret_arg, @arg[$k_idx, $v_idx]; + } } - ($value, @arg); + ($value, @ret_arg); } # }}} _arg_scan Index: lib/POE/Component/SNMP/Dispatcher.pm =================================================================== --- lib/POE/Component/SNMP/Dispatcher.pm (revision 4341) +++ lib/POE/Component/SNMP/Dispatcher.pm (working copy) @@ -92,6 +92,7 @@ DEBUG_INFO('%s', dump_args( [ $pdu, $delay ] )); + no warnings 'redefine'; local *Net::SNMP::Dispatcher::_send_pdu = \&_send_pdu; VERBOSE and DEBUG_INFO('{-------- SUPER::send_pdu()');