From 75a3be852d43742babff74c6b84a7cda6bcb6242 Mon Sep 17 00:00:00 2001 From: brapru Date: Mon, 14 Feb 2022 06:10:59 -0500 Subject: [PATCH] ping: Count argument must be greater than zero Previously, when passing 0 as a count number to the ping utility it would ping the specified host indefinitely. This is obviously not the intended behavior, so forcing the count to be in the range of 1 <= value <= UINT32_MAX resolves the issue. --- Userland/Utilities/ping.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Utilities/ping.cpp b/Userland/Utilities/ping.cpp index 825608112d..4f9ecea2d6 100644 --- a/Userland/Utilities/ping.cpp +++ b/Userland/Utilities/ping.cpp @@ -24,9 +24,9 @@ #include #include -static int total_pings; +static uint32_t total_pings; static int successful_pings; -static int count; +static uint32_t count; static uint32_t total_ms; static int min_ms; static int max_ms; @@ -67,6 +67,11 @@ ErrorOr serenity_main(Main::Arguments arguments) args_parser.add_option(payload_size, "Amount of bytes to send as payload in the ECHO_REQUEST packets.", "size", 's', "size"); args_parser.parse(arguments); + if (count < 1 || count > UINT32_MAX) { + warnln("invalid count argument: '{}': out of range: 1 <= value <= {}", count, UINT32_MAX); + return 1; + } + if (payload_size < 0) { // Use the default. payload_size = 32 - sizeof(struct icmphdr);