From: | CARNIL [...] cpan.org |
Subject: | libnet-snmp-perl: Use of uninitialized value in pattern match (m//) at /usr/share/perl5/Net/SNMP.pm line 2620 |
Hi,
We have the following bug reported to the Debian package of Net-SNMP
(https://bugs.debian.org/908514):
It doesn't seem to be a bug in the packaging, so you may want to take
a look. Thanks!
------8<-----------8<-----------8<-----------8<-----------8<-----
[...]
Hi,
I have a script that uses SNMP.pm to connect to a device via snmp v3. While executing the `open` sub there occures the following error due to a missing check if a variable is defined before it is used:
```
Use of uninitialized value in pattern match (m//) at /usr/share/perl5/Net/SNMP.pm line 2620.
CRITICAL - cannot create session object: Time synchronization failed during discovery
```
The variable `$this->{_error}` at this line is undefined but is beeing access by `$this->{_error} =~ /usmStatsNotInTimeWindows/`. The following patch fixes this problem by first checking if any error occured (`$this->{_error}` is defined) and only then compares its values:
```
--- SNMP.pm.old 2018-09-10 19:19:39.200267652 +0200
+++ SNMP.pm 2018-09-10 19:18:55.449787618 +0200
@@ -2618,7 +2618,7 @@
# assume that the synchronization has failed.
if (($this->{_security}->discovered()) &&
- ($this->{_error} =~ /usmStatsNotInTimeWindows/))
+ ((!$this->{_error}) || $this->{_error} =~ /usmStatsNotInTimeWindows/ ))
{
$this->_error_clear();
DEBUG_INFO('discovery and synchronization complete');
```
------8<-----------8<-----------8<-----------8<-----------8<-----
Thanks for considering,
Salvatore Bonaccorso,
Debian Perl Group