Quellcode durchsuchen

Merge pull request #740 from nagios-plugins/679-check_snmp-no-threshold

Fix #679 by adding whitespace check
Sebastian Wolf vor 2 Jahren
Ursprung
Commit
5c61149820
3 geänderte Dateien mit 12 neuen und 3 gelöschten Zeilen
  1. 1 0
      NEWS
  2. 1 0
      THANKS.in
  3. 10 3
      plugins/check_snmp.c

+ 1 - 0
NEWS

@@ -4,6 +4,7 @@ This file documents the major additions and syntax changes between releases.
 	FIXES
 	check_ntp.pl: Fix warning/critical threshold information missing from performance data output (#735)
 	check_ntp.pl: Fix issues when NTP server has a positive time offset (#734)
+	check_snmp: Fixed issue where plugin returned OK for missin OID (#679)
 
 2.4.6 2023-08-01
 	FIXES

+ 1 - 0
THANKS.in

@@ -144,6 +144,7 @@ Gianluca Varisco
 gino0631
 Grant Byers
 Greg Bowser
+Griffin Westerman
 Guenther Mair
 Guillaume Rousse
 Gunnar Beutner

+ 10 - 3
plugins/check_snmp.c

@@ -94,6 +94,7 @@ void print_usage (void);
 void print_help (void);
 
 #include "regex.h"
+#include <ctype.h>
 char regex_expect[MAX_INPUT_BUFFER] = "";
 regex_t preg;
 regmatch_t pmatch[10];
@@ -203,7 +204,7 @@ main (int argc, char **argv)
 	char *previous_string=NULL;
 	char *ap=NULL;
 	char *state_string=NULL;
-	size_t response_length, current_length, string_length;
+	size_t response_length, current_length, string_length, show_length;
 	char *temp_string=NULL;
 	char *quote_string=NULL;
 	time_t current_time;
@@ -488,9 +489,15 @@ main (int argc, char **argv)
 			show = strpbrk (show, "-0123456789");
 			is_ticks = 1;
 		}
-		else
+		else {
 			show = response;
-
+			show_length = strlen(show);
+			for (int i = 0; i < show_length; i++){
+				if (isspace(show[i])){
+					die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
+				}
+			}
+		}
 		iresult = STATE_DEPENDENT;
 
 		/* Process this block for numeric comparisons */