1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:14:58 +00:00

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.
This commit is contained in:
brapru 2022-02-14 06:10:59 -05:00 committed by Andreas Kling
parent ef3605604e
commit 75a3be852d

View file

@ -24,9 +24,9 @@
#include <time.h>
#include <unistd.h>
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<int> 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);