From 79b27fd9ec69b6b96ad75387f9aa47c963302f55 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 23 Dec 2021 11:52:38 +0100 Subject: [PATCH] ctdb: Allow rfc5952 "[2001:db8::1]:80" ipv6 notation Bug: https://bugzilla.samba.org/show_bug.cgi?id=14934 Signed-off-by: Volker Lendecke --- ctdb/protocol/protocol_util.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 2d0a6f33038..42b50906b73 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -200,12 +200,24 @@ static int ipv4_from_string(const char *str, struct sockaddr_in *ip) static int ipv6_from_string(const char *str, struct sockaddr_in6 *ip6) { + size_t len = strlen(str); + char s[64]; int ret; *ip6 = (struct sockaddr_in6) { .sin6_family = AF_INET6, }; + len = strlcpy(s, str, sizeof(s)); + if (len >= sizeof(s)) { + return EINVAL; + } + + if ((len >= 2) && (s[0] == '[') && (s[len-1] == ']')) { + s[len-1] = '\0'; + str = s+1; + } + ret = inet_pton(AF_INET6, str, &ip6->sin6_addr); if (ret != 1) { return EINVAL; -- 2.30.2