From cff821257bebdbfba87d183726ea9672625c2e77 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 31 Oct 2023 01:47:26 +0100 Subject: check_users: Change option for sanity checking arguments to avoid segfault --- plugins/check_users.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugins/check_users.c b/plugins/check_users.c index 7cf7a2cc..916a691d 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c @@ -227,18 +227,23 @@ process_arguments (int argc, char **argv) } c = optind; + if (warning_range == NULL && argc > c) warning_range = argv[c++]; + if (critical_range == NULL && argc > c) critical_range = argv[c++]; /* this will abort in case of invalid ranges */ set_thresholds (&thlds, warning_range, critical_range); - if (thlds->warning->end < 0) - usage4 (_("Warning threshold must be a positive integer")); - if (thlds->critical->end < 0) - usage4 (_("Critical threshold must be a positive integer")); + if (!thlds->warning) { + usage4 (_("Warning threshold must be a valid range expression")); + } + + if (!thlds->critical) { + usage4 (_("Critical threshold must be a valid range expression")); + } return OK; } -- cgit v1.2.3-74-g34f1 From d9a999de7b182a6dd257f8b6d83067070f51e4c3 Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 31 Oct 2023 01:50:46 +0100 Subject: Enhance tests to check wheter the option validation works --- plugins/t/check_users.t | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t index 9ebc2fc6..21c3e53d 100644 --- a/plugins/t/check_users.t +++ b/plugins/t/check_users.t @@ -13,10 +13,11 @@ use Test; use NPTest; use vars qw($tests); -BEGIN {$tests = 8; plan tests => $tests} +BEGIN {$tests = 12; plan tests => $tests} my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; +my $wrongOptionOutput = '/Usage:/'; my $t; @@ -24,6 +25,8 @@ $t += checkCmd( "./check_users 1000 1000", 0, $successOutput ); $t += checkCmd( "./check_users 0 0", 2, $failureOutput ); $t += checkCmd( "./check_users -w 0:1000 -c 0:1000", 0, $successOutput ); $t += checkCmd( "./check_users -w 0:0 -c 0:0", 2, $failureOutput ); +$t += checkCmd( "./check_users -w 0:1000", 3, $wrongOptionOutput); +$t += checkCmd( "./check_users", 3, $wrongOptionOutput); exit(0) if defined($Test::Harness::VERSION); exit($tests - $t); -- cgit v1.2.3-74-g34f1 From a9d77ac5456fa0366783f7fec2525d4c159fecdf Mon Sep 17 00:00:00 2001 From: RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 31 Oct 2023 01:51:27 +0100 Subject: check_users: Update help to properly show that thresholds are ranges --- plugins/check_users.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/check_users.c b/plugins/check_users.c index 916a691d..89b95369 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c @@ -266,10 +266,10 @@ print_help (void) printf (UT_HELP_VRSN); printf (UT_EXTRA_OPTS); - printf (" %s\n", "-w, --warning=INTEGER"); - printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in")); - printf (" %s\n", "-c, --critical=INTEGER"); - printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in")); + printf (" %s\n", "-w, --warning=RANGE_EXPRESSION"); + printf (" %s\n", _("Set WARNING status if number of logged in users violates RANGE_EXPRESSION")); + printf (" %s\n", "-c, --critical=RANGE_EXPRESSION"); + printf (" %s\n", _("Set CRITICAL status if number of logged in users violates RANGE_EXPRESSION")); printf (UT_SUPPORT); } -- cgit v1.2.3-74-g34f1