Page 1 of 1

[Nagios-devel] patch: nrpe fails to start when config file includes

Posted: Thu Mar 04, 2004 8:10 pm
by Guest
--=-givE5VSSUzOe2Qi1Lq8G
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi,

If nrpe's config file should include a line containing only whitespace,
then it will fail to start. I found this rather tricky to diagnose!

To demonstrate bug:
nrpe -d -c {config-file}
then
ps -efl | grep nrpe

For a config file containing " \n", nrpe will fail to start.

So attached is a simple patch to ignore all whitespace on the start of
any line in the config file. Note that this means that " x=foo" and "
# a comment" will now be regarded as valid rather than invalid as was
previously done (leading whitespace is just ignored).

The patch is in conventional "universal diff" format.
Regards,

Simon


--=-givE5VSSUzOe2Qi1Lq8G
Content-Disposition: attachment; filename=nrpe-space.patch.txt
Content-Type: text/x-patch; name=nrpe-space.patch.txt; charset=
Content-Transfer-Encoding: 7bit

Index: nrpe.c
===================================================================
RCS file: /cvsroot/nagios/nrpe/src/nrpe.c,v
retrieving revision 1.32
diff -u -r1.32 nrpe.c
--- nrpe.c 24 Oct 2003 23:55:14 -0000 1.32
+++ nrpe.c 5 Mar 2004 03:28:37 -0000
@@ -281,6 +281,7 @@
FILE *fp;
char config_file[MAX_FILENAME_LENGTH];
char input_buffer[MAX_INPUT_BUFFER];
+ char *input_line;
char *temp_buffer;
char *varname;
char *varvalue;
@@ -300,17 +301,23 @@
while(fgets(input_buffer,MAX_INPUT_BUFFER-1,fp)){

line++;
+ input_line = input_buffer;
+
+ /* skip leading whitespace */
+ while (isspace(*input_line)) {
+ ++input_line;
+ }

/* skip comments and blank lines */
- if(input_buffer[0]=='#')
+ if(input_line[0]=='#')
continue;
- if(input_buffer[0]=='\x0')
+ if(input_line[0]=='\x0')
continue;
- if(input_buffer[0]=='\n')
+ if(input_line[0]=='\n')
continue;

/* get the variable name */
- varname=strtok(input_buffer,"=");
+ varname=strtok(input_line,"=");
if(varname==NULL){
syslog(LOG_ERR,"No variable name specified in config file '%s' - Line %d\n",filename,line);
return ERROR;
@@ -359,7 +366,7 @@
server_address[sizeof(server_address)-1]='\0';
}

- else if(strstr(input_buffer,"command[")){
+ else if(strstr(input_line,"command[")){
temp_buffer=strtok(varname,"[");
temp_buffer=strtok(NULL,"]");
if(temp_buffer==NULL){

--=-givE5VSSUzOe2Qi1Lq8G--






This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]