Fix garbage in command output
Krzysztof Oledzki
ole at ans.pl
Mon Dec 31 00:55:09 CET 2007
Hello,
This patch properly terminates the "output" string so both returned and logged
(syslog) values are correct.
The bug was introduced in nrpe-2.8 (multiline plugin output) - previously the
child process was able to return a properly termintaed c-string but now, when
fread() is used instead of fgets(), the received string (output) is not
terminated and my_system() returns and logs some kind of garbage.
I also decided to remove two unused variables.
Best regards,
Krzysztof Olędzki
-------------- next part --------------
--- nrpe-2.10-orig/src/nrpe.c 2007-10-19 15:18:57.000000000 +0200
+++ nrpe-2.10/src/nrpe.c 2007-12-31 00:09:58.000000000 +0100
@@ -1255,7 +1255,6 @@
int result;
extern int errno;
char buffer[MAX_INPUT_BUFFER];
- char temp_buffer[MAX_INPUT_BUFFER];
int fd[2];
FILE *fp;
int bytes_read=0;
@@ -1385,14 +1384,15 @@
/* try and read the results from the command output (retry if we encountered a signal) */
if(output!=NULL){
- strcpy(output,"");
- do{
- bytes_read=read(fd[0],output,output_length-1);
- }while(bytes_read==-1 && errno==EINTR);
- }
+ do {
+ bytes_read=read(fd[0], output, output_length-1);
+ } while (bytes_read==-1 && errno==EINTR);
- if(bytes_read==-1 && output!=NULL)
- strcpy(output,"");
+ if (bytes_read==-1)
+ *output = '\0';
+ else
+ output[bytes_read] = '\0';
+ }
/* if there was a critical return code and no output AND the command time exceeded the timeout thresholds, assume a timeout */
if(result==STATE_CRITICAL && bytes_read==-1 && (end_time-start_time)>=timeout){
@@ -1602,7 +1602,6 @@
void sighandler(int sig){
static char *sigs[]={"EXIT","HUP","INT","QUIT","ILL","TRAP","ABRT","BUS","FPE","KILL","USR1","SEGV","USR2","PIPE","ALRM","TERM","STKFLT","CHLD","CONT","STOP","TSTP","TTIN","TTOU","URG","XCPU","XFSZ","VTALRM","PROF","WINCH","IO","PWR","UNUSED","ZERR","DEBUG",(char *)NULL};
int i;
- char temp_buffer[MAX_INPUT_BUFFER];
if(sig<0)
sig=-sig;
-------------- next part --------------
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
-------------- next part --------------
_______________________________________________
Nagios-devel mailing list
Nagios-devel at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-devel
More information about the Developers
mailing list