From c9d451e857b45229a9cd83f3a140ea7b7ec506a0 Mon Sep 17 00:00:00 2001 From: Kareem Date: Thu, 29 May 2025 11:44:26 -0700 Subject: [PATCH] Fix wolfSSL_BIO_new_connect's handling of IPV6 addresses. --- src/bio.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/bio.c b/src/bio.c index 0b52a6c17..446043cf2 100644 --- a/src/bio.c +++ b/src/bio.c @@ -2392,13 +2392,28 @@ int wolfSSL_BIO_flush(WOLFSSL_BIO* bio) WOLFSSL_ENTER("wolfSSL_BIO_new_connect"); bio = wolfSSL_BIO_new(wolfSSL_BIO_s_socket()); if (bio) { - const char* port = XSTRSTR(str, ":"); + const char* port; +#ifdef WOLFSSL_IPV6 + const char* ipv6Start = XSTRSTR(str, "["); + const char* ipv6End = XSTRSTR(str, "]"); + + if (ipv6End) + port = XSTRSTR(ipv6End, ":"); + else +#endif + port = XSTRSTR(str, ":"); if (port != NULL) bio->port = (word16)XATOI(port + 1); else port = str + XSTRLEN(str); /* point to null terminator */ +#ifdef WOLFSSL_IPV6 + if (ipv6Start && ipv6End) { + str = ipv6Start + 1; + port = ipv6End; + } +#endif bio->ip = (char*)XMALLOC( (size_t)(port - str) + 1, /* +1 for null char */ bio->heap, DYNAMIC_TYPE_OPENSSL);