From 18e9be02d421940dfebbac7eb50aaac4817551f9 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 8 Jul 2024 17:24:26 +0200 Subject: [PATCH] tools/nut-scanner/nutscan-ip.c: nutscan_cidr_to_ip(): strip square brackets around first_ip, if any [#2512] Signed-off-by: Jim Klimov --- tools/nut-scanner/nutscan-ip.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/nut-scanner/nutscan-ip.c b/tools/nut-scanner/nutscan-ip.c index cd198d12b9..d1ad62189a 100644 --- a/tools/nut-scanner/nutscan-ip.c +++ b/tools/nut-scanner/nutscan-ip.c @@ -300,10 +300,18 @@ int nutscan_cidr_to_ip(const char * cidr, char ** start_ip, char ** stop_ip) if (mask == NULL) { upsdebugx(0, "WARNING: %s failed to parse mask from cidr=%s (first_ip=%s)", __func__, cidr, first_ip); - free (first_ip); + free(first_ip); free(cidr_tok); return 0; } + + if (first_ip[0] == '[' && first_ip[strlen(first_ip) - 1] == ']') { + char *s = strdup(first_ip + 1); + s[strlen(s) - 1] = '\0'; + free(first_ip); + first_ip = s; + } + upsdebugx(5, "%s: parsed cidr=%s into first_ip=%s and mask=%s", __func__, cidr, first_ip, mask);