Share

Nagios Plugin Development

Tracker: Bugs

7 check_snmp does not allow " chars in cmdline - ID: 1985230
Last Update: Comment added ( dermoth )

The following Bugreport we got against our debian package:

snmpd can be queried for customized "extend"s.
A configured extend like
extend avail_mem /usr/local/bin/check_avail_mem.pl
can be queried as
snmpget -c public -v1 ds9 'nsExtendOutput1Line."avail_mem"'
NET-SNMP-EXTEND-MIB::nsExtendOutput1Line."avail_mem" = STRING: 749764

If you try to query this with check_snmp like
check_snmp -H $HOSTADDRESS$ -C public -o
'nsExtendOutput1Line."syslog-idletime"'
this results into
Could not open pipe: /usr/bin/snmpget -t 1 -r 5 -m ALL -v 1 -c public
ds9:161 nsExtendOutput1Line."syslog-idletime"

Unfortuantely, check_snmp contains code in popen.c that does not allow any
" chars in
the command line and bails out with above error.

I fixed this by commenting out the follwing block:

--- popen.c.old 2008-01-12 14:16:39.000000000 +0100
+++ popen.c 2008-01-12 14:16:54.000000000 +0100
@@ -133,8 +133,10 @@
strcpy (cmd, cmdstring);

/* This is not a shell, so we don't handle "???" */
+/*
if (strstr (cmdstring, "\""))
return NULL;
+*/

/* allow single quotes, but only if non-whitesapce doesn't occur on
both sides */
if (strstr (cmdstring, " ' ") || strstr (cmdstring, "'''"))

You can track the bugreport via
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=460405

Thanks and kind regards, Jan.


Jan Wagner ( cyco_dd ) - 2008-06-05 08:46

7

Closed

None

Ton Voon

Argument proccessing

CVS

Public


Comments ( 10 )

Date: 2009-03-18 11:58
Sender: dermoth

Thanks John. I applied your latest patch.


Date: 2009-03-17 22:34
Sender: jbarbutoSourceForge.net Site Admin

I found a flaw in my patch: the MAX_OIDS limit was no longer being
enforced, allowing for a potential buffer overflow. I've attached a patch
against the git master to fix this.


Date: 2009-03-14 01:29
Sender: tonvoonProject Admin

Applied in git. Manually tested for an OID containing a double quote and
works as expected.

Thanks for John for his patch.


Date: 2009-03-13 23:56
Sender: jbarbutoSourceForge.net Site Admin

I just used the tests in t/check_snmp.t plus a few others more specific to
our environment. Almost all of my extra tests, like the extend tests,
wouldn't necessarily work elsewhere. About the only test you'd find
useful
to add is one of multiple OIDs:

$res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o
host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c
1:,1:");
cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize
and hrSystemProcesses");
like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize
and hrSystemProcesses");




Date: 2009-03-13 22:04
Sender: tonvoonProject Admin

Thanks John! I look through this now.

Out of interest, what tests did you run? Will add them into our test
scripts


Date: 2009-03-13 21:14
Sender: jbarbutoSourceForge.net Site Admin

tonvoon: I see, I thought you were referring to plugins/runcmd.c.

I've attached a patch against the SVN trunk that changes check_snmp to use
lib/utils_cmd.c. It's passed all the tests I've thrown at it, including
extend OIDs. This wasn't a trivial patch, and my C foo isn't great, so
please modify as necessary.




Date: 2009-03-12 11:18
Sender: tonvoonProject Admin

jbarbuto: Can you see the cmd_run and cmd_run_array in lib/utils_cmd.c?
This is also used in negate.c. The idea is that if you pass an array of
arguments, there will not be any shell expansion.

mechanyx: There may be quoting that is required at Nagios. If you use $ in
a command argument, you need to escape it with $$.


Date: 2009-03-11 21:24
Sender: mechanyx

I'm not sure if this is related or not, but I had a similar problem with
check_snmp where the community string on a network device contained a
dollar sign ($). I was unable to get the check to run with that community
string. I apologize as I do not remember exactly what Nagios output when I
tried various methods of quoting or escaping it. I ended up changing the
community string on the device.

Thanks, Rich(ard)


Date: 2009-03-11 20:34
Sender: jbarbutoSourceForge.net Site Admin

I looked into writing a patch using the runcmd library, but I don't see
this function you're referring to.
np_runcmd_open() looks pretty similar to spopen(), with the same double
quotes restriction.

The old exec method of running external commands is deprecated, so I'd
really like to get extend working.


Date: 2009-02-20 00:11
Sender: tonvoonProject Admin

I don't think this is a valid fix. Preferably check_snmp should be switched
to use the runcmd library instead, which has a function to pass a varg list
for the command to run, thereby avoiding shell quotation.


Attached Files ( 2 )

Filename Description Download
check_snmp.patch changes check_snmp to use lib/utils_cmd.c Download
check_snmp_max_oids.patch enforce MAX_OIDS limit Download

Changes ( 8 )

Field Old Value Date By
allow_comments 0 2009-03-18 11:58 dermoth
File Added 318264: check_snmp_max_oids.patch 2009-03-17 22:36 jbarbuto
assigned_to nobody 2009-03-14 01:29 tonvoon
close_date - 2009-03-14 01:29 tonvoon
allow_comments 1 2009-03-14 01:29 tonvoon
status_id Open 2009-03-14 01:29 tonvoon
File Added 317729: check_snmp.patch 2009-03-13 21:19 jbarbuto
priority 5 2009-01-30 21:45 cyco_dd