From c874f950e8e5b6a805d8adf759d521501b22c7ce Mon Sep 17 00:00:00 2001 From: Sven Nierlein Date: Wed, 15 Mar 2023 09:51:18 +0100 Subject: check_snmp: disable multiplier when unused - if no multiplier is set, simply return the given string. Otherwise we would strip off the unit. - if used, allocate new space to hold the result which might be larger than the initial input Signed-off-by: Sven Nierlein --- plugins/check_snmp.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index d3968a27..c4ddd0ed 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -46,6 +46,7 @@ const char *email = "devel@monitoring-plugins.org"; #define DEFAULT_PRIV_PROTOCOL "DES" #define DEFAULT_DELIMITER "=" #define DEFAULT_OUTPUT_DELIMITER " " +#define DEFAULT_BUFFER_SIZE 100 #define mark(a) ((a)!=0?"*":"") @@ -157,6 +158,7 @@ int perf_labels = 1; char* ip_version = ""; double multiplier = 1.0; char *fmtstr = ""; +char buffer[DEFAULT_BUFFER_SIZE]; static char *fix_snmp_range(char *th) { @@ -1169,6 +1171,9 @@ multiply (char *str) double val; char *conv = "%f"; + if(multiplier == 1) + return(str); + if(verbose>2) printf(" multiply input: %s\n", str); @@ -1187,15 +1192,15 @@ multiply (char *str) conv = fmtstr; } if (val == (int)val) { - sprintf(str, "%.0f", val); + snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val); } else { if(verbose>2) printf(" multiply using format: %s\n", conv); - sprintf(str, conv, val); + snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val); } if(verbose>2) - printf(" multiply result: %s\n", str); - return str; + printf(" multiply result: %s\n", buffer); + return buffer; } -- cgit v1.2.3-74-g34f1