[Nagios-devel] utils.c/process_macro() problem with "$" in command line

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] utils.c/process_macro() problem with "$" in command line

Post by Guest »

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

--0-1888119194-1044567457=:95057
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
Content-ID:

I recently found a problem where a trailing "$" was being added to the end
of the command line for one of my checks. After some excessive use of
gdb, and learning a heck of a lot about the Nagios program flow, I traced
it to a command line that has a "$" in one of its options.

The trailing "$" gets added in utils.c in this section:

----- (formatting mangled a bit for E-mail compatibility -----
/* a non-macro, just some user-defined string between two $s */
else{
strncat(output_buffer,"$",buffer_length-strlen(output_buffer)-1);
output_buffer[buffer_length-1]='\x0';
strncat(output_buffer,temp_buffer,
buffer_length-strlen(output_buffer)-1);
output_buffer[buffer_length-1]='\x0';
strncat(output_buffer,"$",buffer_length-strlen(output_buffer)-1);
}
-----

This assumes that my_strtok found something between two "$" and puts the
second one in. However, my_strtok also returns everything from the last
"$" to the end of the line if it doesn't find a second "$", resulting in
the additional trailing "$" that caused my problem.

I didn't try to fix it since I couldn't decide which way would be best,
but here are some ideas I had on how to do it:
+ Don't put on the second $ if it's at end of line (breaks if someone
intended to have a "$" last)
+ Record someplace if my_strtok found a "$" at the end of the line and
only reinsert it if there was one there before (nasty to code)
+ Have my_strtok complain/abort if it doesn't find a second $ before
end of line. (making it an error might be overreacting, though a
warning and a note on using "$$" might be enough.)

Of course, the short term fix was for me to replace the "$" with
"$$" since that gets handled nicely by utils.c.

Attached is a suggested "additional debugging" patch that proved useful
for me, but does not fix the problem.

-- Steve

--0-1888119194-1044567457=:95057
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII; NAME="checks-u.patch"
Content-Transfer-Encoding: BASE64
Content-ID:
Content-Description: checks.c additional debugging patch
Content-Disposition: ATTACHMENT; FILENAME="checks-u.patch"

SW5kZXg6IGNoZWNrcy5jDQo9PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09DQpSQ1Mg
ZmlsZTogL2N2c3Jvb3QvbmFnaW9zL25hZ2lvcy9iYXNlL2NoZWNrcy5jLHYN
CnJldHJpZXZpbmcgcmV2aXNpb24gMS4yMQ0KZGlmZiAtdSAtcjEuMjEgY2hl
Y2tzLmMNCi0tLSBjaGVja3MuYwk4IEphbiAyMDAzIDA0OjA2OjE1IC0wMDAw
CTEuMjENCisrKyBjaGVja3MuYwk2IEZlYiAyMDAzIDIxOjM1OjA3IC0wMDAw
DQpAQCAtMjg4LDYgKzI4OCwxMiBAQA0KIAkgICAgICAgIH0NCiAjZW5kaWYN
CiANCisjaWZkZWYgREVCVUczDQorCS8qIFByaW50IHdoYXQgd2UncmUgcmVh
bGx5IHJ1bm5pbmcgZm9yIGRlYnVnIHB1cnBvc2VzICovDQorCXByaW50Zigi
XHRwcm9jZXNzZWRfY29tbWFuZCBpczogJXNcbiIsIHByb2Nlc3NlZF9jb21t
YW5kKTsNCisjZW5kaWYNCisNCisNCiAJLyogZm9yayBhIGNoaWxkIHByb2Nl
c3MgKi8NCiAJcGlkPWZvcmsoKTsNCiANCg==

--0-1888119194-1044567457=:95057--





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: r1p6os402@sneakemail.com
Locked