From a88236aee36407852f74744668288719e603fa7c Mon Sep 17 00:00:00 2001 From: dwj0 <45187345+dwj0@users.noreply.github.com> Date: Sat, 11 Jun 2022 21:38:44 +0800 Subject: [PATCH] modified scan_address() fixing possible netmask bitlen error when -a provided IP address lacks slash (#1012) --- src/edge.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/edge.c b/src/edge.c index 428f37d..3aa969a 100644 --- a/src/edge.c +++ b/src/edge.c @@ -105,17 +105,14 @@ static int scan_address (char * ip_addr, size_t addr_size, if(!end) // no slash present -- default end end = s + strlen(s); + else + // slash is present. now, handle the sub-network address + sscanf(end + 1, "%u", &bitlen); strncpy(ip_addr, start, (size_t)MIN(end - start, addr_size - 1)); // ensure NULL term - if(end) { - // slash is present - - // now, handle the sub-network address - sscanf(end + 1, "%u", &bitlen); - bitlen = htobe32(bitlen2mask(bitlen)); - inet_ntop(AF_INET, &bitlen, netmask, netmask_size); - } + bitlen = htobe32(bitlen2mask(bitlen)); + inet_ntop(AF_INET, &bitlen, netmask, netmask_size); return retval; }