Просмотр исходного кода

check_snmp: Update last patch to copy value verbatim

Rework last patch, copying the converted portion of the string rather
than re-converting it. This is safer for backwards-compatibility as the
value is never modified.
Thomas Guyot-Sionnest 16 лет назад
Родитель
Сommit
e5690e3dda
1 измененных файлов с 6 добавлено и 10 удалено
  1. 6 10
      plugins/check_snmp.c

+ 6 - 10
plugins/check_snmp.c

@@ -117,12 +117,11 @@ int needmibs = FALSE;
 int
 int
 main (int argc, char **argv)
 main (int argc, char **argv)
 {
 {
-	int i;
+	int i, len;
 	int iresult = STATE_UNKNOWN;
 	int iresult = STATE_UNKNOWN;
 	int result = STATE_UNKNOWN;
 	int result = STATE_UNKNOWN;
 	int return_code = 0;
 	int return_code = 0;
 	int external_error = 0;
 	int external_error = 0;
-	double perftmp;
 	char **command_line = NULL;
 	char **command_line = NULL;
 	char *cl_hidden_auth = NULL;
 	char *cl_hidden_auth = NULL;
 	char *oidname = NULL;
 	char *oidname = NULL;
@@ -352,17 +351,14 @@ main (int argc, char **argv)
 		if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
 		if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
 			asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
 			asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
 
 
-		/* Try a two-way conversion of show and add perfdata only if we get
-		 * something back at the end */
+		/* Write perfdata with whatever can be parsed by strtod, if possible */
 		ptr = NULL;
 		ptr = NULL;
-		perftmp = strtod(show, &ptr);
-		if (ptr != show) {
-			ptr = NULL;
-			asprintf(&ptr, "%0.9g", perftmp);
+		strtod(show, &ptr);
+		if (ptr > show) {
 			strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
 			strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
 			strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
 			strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
-			strncat(perfstr, ptr, sizeof(perfstr)-strlen(perfstr)-1);
-			free(ptr);
+			len = sizeof(perfstr)-strlen(perfstr)-1;
+			strncat(perfstr, show, len>ptr-show ? ptr-show : len);
 
 
 			if (type)
 			if (type)
 				strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
 				strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);