File nrpe-return_value.patch of Package nagios-nrpe

Index: src/nrpe.c
===================================================================
--- src/nrpe.c.orig
+++ src/nrpe.c
@@ -94,9 +94,15 @@ int main(int argc, char **argv){
 #endif
 
 	/* set some environment variables */
-	asprintf(&env_string,"NRPE_MULTILINESUPPORT=1");
+	if (asprintf(&env_string,"NRPE_MULTILINESUPPORT=1") == -1){
+		fprintf(stderr, "Failed to allocate string for NRPE_MULTILINESUPPORT\n");
+		return STATE_CRITICAL;
+	}
 	putenv(env_string);
-	asprintf(&env_string,"NRPE_PROGRAMVERSION=%s",PROGRAM_VERSION);
+	if (asprintf(&env_string,"NRPE_PROGRAMVERSION=%s",PROGRAM_VERSION) == -1){
+		fprintf(stderr,"Failed to allocate string for NRPE_PROGRAMVERSION\n");
+		return STATE_CRITICAL;
+	}
 	putenv(env_string);
 
 	/* process command-line args */
@@ -179,7 +185,10 @@ int main(int argc, char **argv){
 
 		/* get absolute path of current working directory */
 		strcpy(config_file,"");
-		getcwd(config_file,sizeof(config_file));
+		if (getcwd(config_file,sizeof(config_file)) == NULL){
+			fprintf(stderr,"Failed to get absolute path of current working directory\n");
+			return STATE_CRITICAL;
+		}
 
 		/* append a forward slash */
 		strncat(config_file,"/",sizeof(config_file)-2);
@@ -286,7 +295,10 @@ int main(int argc, char **argv){
 		open("/dev/null",O_WRONLY);
 		open("/dev/null",O_WRONLY);
 
-		chdir("/");
+		if (chdir("/") == -1){
+			fprintf(stderr,"Failed to chdir into /\n");
+			return STATE_CRITICAL;
+		}
 		/*umask(0);*/
 
 		/* handle signals */
@@ -1343,7 +1355,10 @@ int my_system(char *command,int timeout,
 	        return STATE_OK;
 
 	/* create a pipe */
-	pipe(fd);
+	if (pipe(fd) == -1){
+		fprintf(stderr,"Faiiled to create a pipe\n");
+		return STATE_CRITICAL;
+	}
 
 	/* make the pipe non-blocking */
 	fcntl(fd[0],F_SETFL,O_NONBLOCK);
@@ -1396,7 +1411,10 @@ int my_system(char *command,int timeout,
 			buffer[sizeof(buffer)-1]='\x0';
 
 			/* write the error back to the parent process */
-			write(fd[1],buffer,strlen(buffer)+1);
+			if (write(fd[1],buffer,strlen(buffer)+1) == -1){
+				fprintf(stderr,"Failed to write the error back to the parent process\n");
+				return STATE_CRITICAL;
+			}
 
 			result=STATE_CRITICAL;
 		        }
@@ -1406,7 +1424,10 @@ int my_system(char *command,int timeout,
 			while((bytes_read=fread(buffer,1,sizeof(buffer)-1,fp))>0){
 
 				/* write the output back to the parent process */
-				write(fd[1],buffer,bytes_read);
+				if (write(fd[1],buffer,bytes_read) == -1){
+					fprintf(stderr,"Failed to write the output back to the parent process\n");
+					return STATE_CRITICAL;
+				}
 				}
 
 			/* close the command and get termination status */
@@ -1618,7 +1639,10 @@ int write_pid_file(void){
 	/* write new pid file */
 	if((fd=open(pid_file,O_WRONLY | O_CREAT,0644))>=0){
 		sprintf(pbuf,"%d\n",(int)getpid());
-		write(fd,pbuf,strlen(pbuf));
+		if (write(fd,pbuf,strlen(pbuf)) == -1){
+			fprintf(stderr,"Failed to write new pid file\n");
+			return STATE_CRITICAL;
+		}
 		close(fd);
 		wrote_pid_file=TRUE;
 	        }
openSUSE Build Service is sponsored by