[icinga-checkins] icinga.org: icinga-core/rbartels/1.3: core: fix problem with extra whitespace in command definition and ePN ( Jason Young) #918

git at icinga.org git at icinga.org
Thu Nov 11 19:54:26 CET 2010


Module: icinga-core
Branch: rbartels/1.3
Commit: 496cac8fee43ab0bcf9490a853588f83cc89e398
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=496cac8fee43ab0bcf9490a853588f83cc89e398

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Thu Nov  4 18:20:12 2010 +0100

core: fix problem with extra whitespace in command definition and ePN (Jason Young) #918

--SNIP--
If a command definition contains extra whitespace between the
filename and the first argument, this gets passed to the embedded
perl plugin as an empty string for the first argument. For example:

define command {
  command_name  test_check
  command_line  $USER1$/test_check.pl    $HOSTADDRESS$ $_HOSTSNMP$
                                      ^^^
}

will result in the plugin seeing $ARGV[0] as "".

This can cause the plugin to improperly interpret the arguments and
fail. Obviously the simple solution is to make sure your configuration
file does not have the extra spaces. However, this issue can be resolved
either in the p1.pl file or the c code. I have included patch files for
both options for your review. I am not an expert c programmer, so there
may be a better way to do this. The issue lies in the way
Text::ParseWords::parse_line handles leading whitespace. The shellwords
function performs the same task, but removes the leading whitespace.
--SNIP--

kudos to Jason Young.

refs #918

---

 Changelog     |    1 +
 THANKS        |    1 +
 base/checks.c |   11 ++++++++---
 p1.pl         |    6 +++---
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/Changelog b/Changelog
index b92eca4..ac614f3 100644
--- a/Changelog
+++ b/Changelog
@@ -14,6 +14,7 @@ FIXES
 * core: base/utils: Refactor my_fcopy() (Andreas Ericsson) #427
 * core: base/nebmods: Replace local file-copy hack with my_fdcopy() (Andreas Ericsson) #424
 * core: force my_free() macro users to end the statement with a semi-colon (Andreas Ericsson) #927
+* core: fix problem with extra whitespace in command definition and ePN (Jason Young) #918
 
 * classic ui: change servicestatus letter color to default black, not grey #946
 * classic ui: fix waste of cpu in status summary (TomTom) #933
diff --git a/THANKS b/THANKS
index cb04d86..8711197 100644
--- a/THANKS
+++ b/THANKS
@@ -319,6 +319,7 @@ in various ways.  If we missed your name, let us know.
 * Greg Woods
 * Cliff Woolley
 * Mitch Wright
+* Jason Young
 * Michal Zimen
 * Dennis van Zuijlekom
 * Pawel Zuzelski
diff --git a/base/checks.c b/base/checks.c
index 796917a..3bfd554 100644
--- a/base/checks.c
+++ b/base/checks.c
@@ -508,6 +508,7 @@ int run_async_service_check(service *svc, int check_options, double latency, int
 	char fname[512]="";
 	char *args[5]={"",DO_CLEAN, "", "", NULL };
 	char *perl_plugin_output=NULL;
+	char *args3=NULL;
 	SV *plugin_hndlr_cr=NULL; /* perl.h holds typedef struct */
 	STRLEN n_a ;
 	int count ;
@@ -704,10 +705,14 @@ int run_async_service_check(service *svc, int check_options, double latency, int
 		args[0]=fname;
 		args[2]="";
 
-		if(strchr(processed_command,' ')==NULL)
+		if(strchr(processed_command,' ')==NULL){
 			args[3]="";
-		else
-			args[3]=processed_command+strlen(fname)+1;
+		} else {
+			/* make sure to strip leading whitespaces from args */
+			args3=processed_command+strlen(fname)+1;
+			for (;isspace(*args3);args3++);
+			args[3]=args3;
+		}
 
 		ENTER;
 		SAVETMPS;
diff --git a/p1.pl b/p1.pl
index 0076cbe..3716ec4 100644
--- a/p1.pl
+++ b/p1.pl
@@ -4,7 +4,7 @@
 
 use strict ;
 
-use Text::ParseWords qw(parse_line) ;
+use Text::ParseWords qw(shellwords) ;
 
 use constant	LEAVE_MSG		=> 1 ;
 use constant	CACHE_DUMP		=> 2 ;
@@ -150,7 +150,7 @@ sub eval_file {
 								# 2 return the error from a former compilation
 								#   if there was one.
 
-			$Cache{$filename}[PLUGIN_ARGS]{$plugin_args} ||= [ parse_line('\s+', 0, $plugin_args) ]
+			$Cache{$filename}[PLUGIN_ARGS]{$plugin_args} ||= [ shellwords($plugin_args) ]
 				if $plugin_args ;
 
 			if ( $Cache{$filename}[PLUGIN_ERROR] ) {
@@ -166,7 +166,7 @@ sub eval_file {
 
 	my $package	= valid_package_name($filename) ;
 
-	$Cache{$filename}[PLUGIN_ARGS]{$plugin_args} ||= [ parse_line('\s+', 0, $plugin_args) ]
+	$Cache{$filename}[PLUGIN_ARGS]{$plugin_args} ||= [ shellwords($plugin_args) ]
 		if $plugin_args ;
 
 	local *FH;





More information about the icinga-checkins mailing list