[Nagiosplug-help] problem with snmp plugin

Grae Noble Grae.Noble at newcastle.edu.au
Thu Aug 8 20:20:03 CEST 2002


Hi All,

I'm having a problem with the check_snmp plugin.

running it without -w -c seems fine, however when I add these options,
I get "Bus Error"
I did have to make a VERY small change to ge the code working with
NET-SNMP version: 5.0.2 (below)

I'm no C expert, hopefully someone can spot something I'm missing.

Details below:

 plugins/check_snmp -H banerjee.newcastle.edu.au -o
.1.3.6.1.2.1.28.2.1.4.1.8 -w 0:200 -c 400:600
Bus Error

 plugins/check_snmp -H banerjee.newcastle.edu.au -o
.1.3.6.1.2.1.28.2.1.4.1.8
SNMP OK - 295

 /usr/local/snmp/bin/snmpget  -m ALL -v 1 -c public 
banerjee.newcastle.edu.au  .1.3.6.1.2.1.28.2.1.4.1.8
MTA-MIB::mtaGroupStoredMessages.1.8 = Gauge32: 295

using gdb 
—----------

 gdb plugins/check_snmp
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and
you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for
details.
This GDB was configured as "sparc-sun-solaris2.8"...
(gdb) break main
Breakpoint 1 at 0x11b90: file check_snmp.c, line 136.
(gdb) run  -H banerjee.newcastle.edu.au -o .1.3.6.1.2.1.28.2.1.4.1.8 -w
200 -c 300
Starting program:
/home/grae/programs/nagios/cvs/nagiosplug/plugins/check_snmp -H
banerjee.newcastle.edu.au -o .1.3.6.1.2.1.28.2.1.4.1.8 -w 200 -c 300

Breakpoint 1, main (argc=-13893508, argv=0xffbef7dc) at
check_snmp.c:136
136             labels = malloc (labels_size);
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0xff242974 in _free_unlocked () from /usr/lib/libc.so.1
(gdb) bt
#0  0xff242974 in _free_unlocked () from /usr/lib/libc.so.1
#1  0xff24292c in free () from /usr/lib/libc.so.1
#2  0x13f8c in ssprintf (ptr=0x2ba31 "295", fmt=0x15a08 "%d") at
utils.c:547
#3  0x1200c in main (argc=178737, argv=0x0) at check_snmp.c:225
(gdb) break utils.c:547
Breakpoint 2 at 0x13f84: file utils.c, line 547.
(gdb) run  -H banerjee.newcastle.edu.au -o .1.3.6.1.2.1.28.2.1.4.1.8 -w
200 -c 300
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Starting program:
/home/grae/programs/nagios/cvs/nagiosplug/plugins/check_snmp -H
banerjee.newcastle.edu.au -o .1.3.6.1.2.1.28.2.1.4.1.8 -w 200 -c 300

Breakpoint 1, main (argc=-13893508, argv=0xffbef7dc) at
check_snmp.c:136
136             labels = malloc (labels_size);
(gdb) c
Continuing.

Breakpoint 2, ssprintf (ptr=0x2ba31 "295", fmt=0x15a08 "%d") at
utils.c:547
547                                             free (ptr);
(gdb) s

Program received signal SIGSEGV, Segmentation fault.
0xff242974 in _free_unlocked () from /usr/lib/libc.so.1
(gdb)



The offending bit of code seems to be:
vi util.c

 while (1) {

                nchars = vsnprintf (str, size, fmt, ap);

                if (nchars > -1)
                        if (nchars < (int) size) {
                                va_end (ap);
                                str[nchars] = '\0';
                                if (ptr)
Segfault happens here ==>            free (ptr);
                               return str;
                        }
                        else {
                                size = (size_t) (nchars + 1);
                        }

                else
                        size *= 2;

                str = realloc (str, size);

                if (str == NULL)
                        terminate (STATE_UNKNOWN, "realloc failed in
ssprintf");
        }

Can't see why this would be a problem.

Changes made:
—----------------

I changed check_snmp.c:149

 command_line = ssprintf
                (command_line,
                 "%s -m ALL -v 1 -c %s %s %s",
                 PATH_TO_SNMPGET, community, server_address, oid);

to get it to work with this version of snmpget. I don't think this is
the problem as it only formats the options passed to snmpget.

Versions:
—--------
gcc 2.95.3
 gmake --version   GNU Make version 3.79.1


Any help appreciated.



Grae Noble
Communication and Information Services, University Services Division
University of Newcastle, NSW
Phone:  +61 2 4921 7875 Fax:  +61 2 4921 7087
Grae.Noble at newcastle.edu.au 
Room: CT216






More information about the Help mailing list