From 401c5dcf444b50d4fffa66f790aa0ee6a919a967 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 30 Apr 2023 22:12:57 +0200 Subject: Fix missing error checks for strtoul(3) --- main.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 7fca16d..c7481d0 100644 --- a/main.c +++ b/main.c @@ -1107,11 +1107,12 @@ static int parse_args(const int argc, char *const argv[], case 'p': { - const unsigned long portul = strtoul(optarg, NULL, 10); + char *endptr; + const unsigned long portul = strtoul(optarg, &endptr, 10); - if (portul > UINT16_MAX) + if (*endptr || portul > UINT16_MAX) { - fprintf(stderr, "%s: invalid port %lu\n", __func__, portul); + fprintf(stderr, "%s: invalid port %s\n", __func__, optarg); return -1; } -- cgit v1.2.3