From 19dc0039365e5cae0ed866c10202c50338f70b0a Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Sat, 7 Oct 2023 11:48:57 +0200 Subject: Do some actual error checking on the threshold parser --- plugins-root/check_icmp.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c index c71ea29c..7140aa50 100644 --- a/plugins-root/check_icmp.c +++ b/plugins-root/check_icmp.c @@ -526,7 +526,8 @@ main(int argc, char **argv) /* Reset argument scanning */ optind = 1; - unsigned long size; + unsigned long size; + bool err; /* parse the arguments */ for(i = 1; i < argc; i++) { while((arg = getopt(argc, argv, opts_str)) != EOF) { @@ -591,23 +592,48 @@ main(int argc, char **argv) exit (STATE_UNKNOWN); break; case 'R': /* RTA mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_rta_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_rta_mode); + + if (!err) { + crash("Failed to parse RTA threshold"); + } + rta_mode=true; break; case 'P': /* packet loss mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_packet_loss_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_packet_loss_mode); + + if (!err) { + crash("Failed to parse packet loss threshold"); + } + pl_mode=true; break; case 'J': /* jitter mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_jitter_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_jitter_mode); + + if (!err) { + crash("Failed to parse jitter threshold"); + } + jitter_mode=true; break; case 'M': /* MOS mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_mos_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_mos_mode); + + if (!err) { + crash("Failed to parse MOS threshold"); + } + mos_mode=true; break; case 'S': /* score mode */ - get_threshold2(optarg, strlen(optarg), &warn, &crit, const_score_mode); + err = get_threshold2(optarg, strlen(optarg), &warn, &crit, const_score_mode); + + if (!err) { + crash("Failed to parse score threshold"); + } + score_mode=true; break; case 'O': /* out of order mode */ -- cgit v1.2.3-74-g34f1