From adb8fcae285e59356375946386a0eed0ddecccf5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 29 Dec 2021 15:10:28 +0100 Subject: [PATCH 1/3] ctdb: rindex->strrchr According to "man rindex" on debian bullseye rindex() was deprecated in Posix.1-2001 and removed from Posix.1-2008. Signed-off-by: Volker Lendecke --- ctdb/protocol/protocol_util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 2d0a6f33038..1f1d874167a 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -230,10 +230,10 @@ static int ip_from_string(const char *str, ctdb_sock_addr *addr) /* IPv4 or IPv6 address? * - * Use rindex() because we need the right-most ':' below for + * Use strrchr() because we need the right-most ':' below for * IPv4-mapped IPv6 addresses anyway... */ - p = rindex(str, ':'); + p = strrchr(str, ':'); if (p == NULL) { ret = ipv4_from_string(str, &addr->ip); } else { @@ -286,7 +286,7 @@ int ctdb_sock_addr_from_string(const char *str, return EINVAL; } - p = rindex(s, ':'); + p = strrchr(s, ':'); if (p == NULL) { return EINVAL; } @@ -324,7 +324,7 @@ int ctdb_sock_addr_mask_from_string(const char *str, return EINVAL; } - p = rindex(s, '/'); + p = strrchr(s, '/'); if (p == NULL) { return EINVAL; } -- 2.30.2 From 79dccc1b04ff1ab5ef10ecc901f03c8f79594b47 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 29 Dec 2021 14:46:14 +0100 Subject: [PATCH 2/3] ctdb: Save 50 bytes .text segment Having this as a small static .text is simpler than having to create this on the stack. Signed-off-by: Volker Lendecke --- ctdb/protocol/protocol_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 1f1d874167a..0a0998f1847 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -237,7 +237,7 @@ static int ip_from_string(const char *str, ctdb_sock_addr *addr) if (p == NULL) { ret = ipv4_from_string(str, &addr->ip); } else { - uint8_t ipv4_mapped_prefix[12] = { + static const uint8_t ipv4_mapped_prefix[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff }; -- 2.30.2 From 3f9b838c4fa86943338ba4bcd0323767cf18c8c5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 23 Dec 2021 11:52:38 +0100 Subject: [PATCH 3/3] 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c index 0a0998f1847..c5d0eb6480e 100644 --- a/ctdb/protocol/protocol_util.c +++ b/ctdb/protocol/protocol_util.c @@ -240,6 +240,19 @@ static int ip_from_string(const char *str, ctdb_sock_addr *addr) static const uint8_t ipv4_mapped_prefix[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff }; + size_t len = strlen(str); + char s[64]; + + 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; + p = strrchr(str, ':'); + } ret = ipv6_from_string(str, &addr->ip6); if (ret != 0) { -- 2.30.2