From 51e6dcee3db18b0be299745c04dbdd917433db7d Mon Sep 17 00:00:00 2001
From: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
Date: Wed, 21 Oct 2026 10:10:53 -0300
Subject: Require libidn2 pkg-config metadata
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
---
 ConfigureChecks.cmake | 19 +------------------
 src/tls/tqca-tls.cpp  |  4 +++-
 2 files changed, 4 insertions(+), 19 deletions(-)

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 04e96b7..b12a7b4 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -38,24 +38,7 @@ if( BUILD_TQCA_TLS )
 ##### check for libidn2
 pkg_search_module( IDN2 QUIET libidn2>=2.2.0 )
 if( NOT IDN2_FOUND )
-    find_path( IDN2_INCLUDE_DIR idn2.h )
-    find_library( IDN2_LIBRARY NAMES idn2 )
-    if( IDN2_INCLUDE_DIR AND IDN2_LIBRARY )
-        set( CMAKE_REQUIRED_INCLUDES "${IDN2_INCLUDE_DIR}" )
-        set( CMAKE_REQUIRED_LIBRARIES "${IDN2_LIBRARY}" )
-        check_cxx_source_compiles( "#include <idn2.h>
-#if !defined(IDN2_VERSION_NUMBER) || IDN2_VERSION_NUMBER < 0x02020000
-#error libidn2 2.2.0 or newer is required
-#endif
-int main() { return idn2_check_version(\"2.2.0\") == 0; }" IDN2_VERSION_SUPPORTED )
-        unset( CMAKE_REQUIRED_INCLUDES )
-        unset( CMAKE_REQUIRED_LIBRARIES )
-    endif()
-    if( NOT IDN2_INCLUDE_DIR OR NOT IDN2_LIBRARY OR NOT IDN2_VERSION_SUPPORTED )
-        tde_message_fatal( "libidn2 2.2.0 or newer is required when the TLS plugin is enabled (install the development package or make libidn2.pc available to pkg-config)" )
-    endif()
-    set( IDN2_INCLUDE_DIRS "${IDN2_INCLUDE_DIR}" )
-    set( IDN2_LIBRARIES "${IDN2_LIBRARY}" )
+    tde_message_fatal( "libidn2 2.2.0 or newer is required when the TLS plugin is enabled (install the development package providing libidn2.pc)" )
 endif()
 
 ##### check for openssl
diff --git a/src/tls/tqca-tls.cpp b/src/tls/tqca-tls.cpp
index b24628d..38174f7 100644
--- a/src/tls/tqca-tls.cpp
+++ b/src/tls/tqca-tls.cpp
@@ -747,6 +747,7 @@ static bool domainToAscii(const TQString &host, TQString *asciiHost)
 				return false;
 		}
 		else {
+			// Short-circuit before i - 1 when this is an empty label.
 			if(labelLength == 0 || converted[i - 1] == '-')
 				return false;
 			labelLength = 0;
@@ -921,7 +922,8 @@ public:
 		TQString ipText = peerHost.lower();
 		if(ipText.startsWith("[") && ipText.endsWith("]"))
 			ipText = ipText.mid(1, ipText.length()-2);
-		bool isIPLiteral = ipText.contains(":") || TQRegExp("^[0-9]+(\\.[0-9]+)+$").exactMatch(ipText);
+		bool isIPLiteral = ipText.contains(":") ||
+			TQRegExp("^[0-9]+(\\.[0-9]+){3}$").exactMatch(ipText);
 		ASN1_OCTET_STRING *peerIP = isIPLiteral ? a2i_IPADDRESS(ipText.latin1()) : nullptr;
 		if(isIPLiteral) {
 			if(!peerIP)
-- 
cgit v1.2.3

