summaryrefslogtreecommitdiffstats
path: root/plugins/check_snmp.c
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2010-03-31 06:45:45 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2010-03-31 23:55:47 (GMT)
commite5690e3ddaebdd98bfd96c2303453e4e0d7ed318 (patch)
tree3e19b1885c746c3311e8d4abec34a831f38accc9 /plugins/check_snmp.c
parent120985853e71d6f20d598d1968f0df9db5163957 (diff)
downloadmonitoring-plugins-e5690e3ddaebdd98bfd96c2303453e4e0d7ed318.tar.gz
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.
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r--plugins/check_snmp.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index ce3919d..fdb5819 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -117,12 +117,11 @@ int needmibs = FALSE;
117int 117int
118main (int argc, char **argv) 118main (int argc, char **argv)
119{ 119{
120 int i; 120 int i, len;
121 int iresult = STATE_UNKNOWN; 121 int iresult = STATE_UNKNOWN;
122 int result = STATE_UNKNOWN; 122 int result = STATE_UNKNOWN;
123 int return_code = 0; 123 int return_code = 0;
124 int external_error = 0; 124 int external_error = 0;
125 double perftmp;
126 char **command_line = NULL; 125 char **command_line = NULL;
127 char *cl_hidden_auth = NULL; 126 char *cl_hidden_auth = NULL;
128 char *oidname = NULL; 127 char *oidname = NULL;
@@ -352,17 +351,14 @@ main (int argc, char **argv)
352 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) 351 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
353 asprintf (&outbuff, "%s %s", outbuff, unitv[i]); 352 asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
354 353
355 /* Try a two-way conversion of show and add perfdata only if we get 354 /* Write perfdata with whatever can be parsed by strtod, if possible */
356 * something back at the end */
357 ptr = NULL; 355 ptr = NULL;
358 perftmp = strtod(show, &ptr); 356 strtod(show, &ptr);
359 if (ptr != show) { 357 if (ptr > show) {
360 ptr = NULL;
361 asprintf(&ptr, "%0.9g", perftmp);
362 strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1); 358 strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
363 strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1); 359 strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
364 strncat(perfstr, ptr, sizeof(perfstr)-strlen(perfstr)-1); 360 len = sizeof(perfstr)-strlen(perfstr)-1;
365 free(ptr); 361 strncat(perfstr, show, len>ptr-show ? ptr-show : len);
366 362
367 if (type) 363 if (type)
368 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); 364 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);