summaryrefslogtreecommitdiffstats
path: root/plugins-root/check_icmp.c
diff options
context:
space:
mode:
authorHolger Weiss <holger@zedat.fu-berlin.de>2026-06-30 15:32:40 +0200
committerHolger Weiss <holger@zedat.fu-berlin.de>2026-06-30 15:32:40 +0200
commitc35c12e58d326ffbd6cfb3c9097653f9f3fb2f4a (patch)
treeda6830ef72c44ef181fa8fbc18ecde140e630e3d /plugins-root/check_icmp.c
parent1c84da06be317a00c667cb7d7f0c24b7e8feb89d (diff)
downloadmonitoring-plugins-c35c12e58d326ffbd6cfb3c9097653f9f3fb2f4a.tar.gz
check_icmp: Reject more than 65535 target hosts
The number of -H hosts is counted into an unsigned short, so supplying more than 65535 hosts wraps the counter. The subsequent calloc(3) then allocates an undersized hosts array while the later parsing loop still writes one entry per host, overflowing the heap buffer. As process_arguments() runs before we drop privileges via setuid(getuid()), this happens while still running as root on setuid-root installs. Guard both places where the counter is incremented and bail out with a usage error once 65535 hosts are reached, rather than wrapping silently. Reported-by: Christopher Kreft <Email@ChristopherKreft.de>
Diffstat (limited to 'plugins-root/check_icmp.c')
-rw-r--r--plugins-root/check_icmp.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/plugins-root/check_icmp.c b/plugins-root/check_icmp.c
index 1390a03e..f3c83ee0 100644
--- a/plugins-root/check_icmp.c
+++ b/plugins-root/check_icmp.c
@@ -361,6 +361,9 @@ check_icmp_config_wrapper process_arguments(int argc, char **argv) {
361 enforced_ai_family = AF_INET6; 361 enforced_ai_family = AF_INET6;
362 break; 362 break;
363 case 'H': { 363 case 'H': {
364 if (result.config.number_of_hosts == USHRT_MAX) {
365 usage_va("Number of specified hosts exceeds %u", USHRT_MAX);
366 }
364 result.config.number_of_hosts++; 367 result.config.number_of_hosts++;
365 break; 368 break;
366 } 369 }
@@ -378,6 +381,9 @@ check_icmp_config_wrapper process_arguments(int argc, char **argv) {
378 381
379 char **tmp = &argv[optind]; 382 char **tmp = &argv[optind];
380 while (*tmp) { 383 while (*tmp) {
384 if (result.config.number_of_hosts == USHRT_MAX) {
385 usage_va("Number of specified hosts exceeds %u", USHRT_MAX);
386 }
381 result.config.number_of_hosts++; 387 result.config.number_of_hosts++;
382 tmp++; 388 tmp++;
383 } 389 }