Browse Source

Merge pull request #749 from nagios-plugins/743-check_snmp-2.0

Potential robust fix for check_snmp issues
Sebastian Wolf 1 year ago
parent
commit
f0a53b8c5a
2 changed files with 10 additions and 5 deletions
  1. 4 0
      NEWS
  2. 6 5
      plugins/check_snmp.c

+ 4 - 0
NEWS

@@ -1,5 +1,9 @@
 This file documents the major additions and syntax changes between releases.
 
+2.4.9
+	FIXES
+	check_snmp: Robustly fixes incorrect integer return value parsing (#749)
+
 2.4.8 2023-12-7
 	FIXES
 	check_snmp: Fixed issue where Timeticks would incorrectly show "No valid data returned" (#743)

+ 6 - 5
plugins/check_snmp.c

@@ -494,7 +494,7 @@ main (int argc, char **argv)
 			show_length = strlen(show);
 			for (j = 0; j < show_length; j++){
 				if (isspace(show[j])){
-					die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
+					die (STATE_UNKNOWN,_("Unrecognized OID name returned (%s)\n"), show);
 				}
 			}
 		}
@@ -504,11 +504,12 @@ main (int argc, char **argv)
 		/* Make some special values,like Timeticks numeric only if a threshold is defined */
 		if (thlds[i]->warning || thlds[i]->critical || calculate_rate || is_ticks || offset != 0.0 || multiplier != 1.0) {
 			/* Find the first instance of the '(' character - the value of the OID should be contained in parens */
-			ptr = strpbrk(show, "(");
-			if (ptr == NULL)
+			if ((ptr = strpbrk(show, "(")) != NULL) { /* Timetick */
+				ptr++;
+			} else if ((ptr = strpbrk(show, "-0123456789")) == NULL) { /* Counter, gauge, or integer */
 				die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
-			ptr++; /* Move to the first character after the '(' */
-			
+			}
+
 			while (i >= response_size) {
 				response_size += OID_COUNT_STEP;
 				response_value = realloc(response_value, response_size * sizeof(*response_value));