git: 399af2d69e83 - main - databases/freetds: Runtime fix with latest openssl

From: Muhammad Moinur Rahman <bofh_at_FreeBSD.org>
Date: Tue, 31 May 2022 06:18:28 UTC
The branch main has been updated by bofh:

URL: https://cgit.FreeBSD.org/ports/commit/?id=399af2d69e8383a7e77ba9dfa0e3bd02bbdc9ab6

commit 399af2d69e8383a7e77ba9dfa0e3bd02bbdc9ab6
Author:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
AuthorDate: 2022-05-31 06:14:13 +0000
Commit:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
CommitDate: 2022-05-31 06:14:13 +0000

    databases/freetds: Runtime fix with latest openssl
    
    - FreeTDS fails to connect with MsSQL after the latest updates of
      OpenSSL specially after the release of 13.1 SNAPSHOTS including
      13.1-RELEASE and more specifically when openssl turned into 1.1.1l
      See the following for more details:
      https://github.com/FreeTDS/freetds/issues/458
    - After the upgrade to version 1.3.9 FreeTDS fails to upgrade when using
      ports tree. [1]
    
    PR:             261967 263641 [1]
    Reported by:    jsc@ntu.edu.tw eugen [1]
---
 databases/freetds/Makefile                  |  4 +-
 databases/freetds/files/patch-src_tds_tls.c | 70 ++++++++++++++++++++++++++---
 2 files changed, 68 insertions(+), 6 deletions(-)

diff --git a/databases/freetds/Makefile b/databases/freetds/Makefile
index a9cce45c5a65..0283890c5679 100644
--- a/databases/freetds/Makefile
+++ b/databases/freetds/Makefile
@@ -2,6 +2,7 @@
 
 PORTNAME=	freetds
 PORTVERSION=	1.3.10
+PORTREVISION=	1
 PORTEPOCH=	1
 CATEGORIES=	databases
 MASTER_SITES=	https://www.freetds.org/files/stable/ \
@@ -75,7 +76,8 @@ post-patch:
 		 ${WRKSRC}/Makefile.am
 	@${REINPLACE_CMD} -e 's|/pool.conf|/pool.conf.sample|g' \
 		 ${WRKSRC}/src/pool/Makefile.am
-	@${REINPLACE_CMD} -e 's|\($$with_iodbc/include\)|\1/libiodbc|g' \
+	@${REINPLACE_CMD} -e 's|\($$with_iodbc/include\)|\1/libiodbc|g ; \
+		 s| odbcss.h||g' \
 		${WRKSRC}/configure.ac
 
 post-install:
diff --git a/databases/freetds/files/patch-src_tds_tls.c b/databases/freetds/files/patch-src_tds_tls.c
index 07a8cb8ec5ac..35612e6faff3 100644
--- a/databases/freetds/files/patch-src_tds_tls.c
+++ b/databases/freetds/files/patch-src_tds_tls.c
@@ -1,6 +1,6 @@
---- src/tds/tls.c.orig	2017-11-30 09:00:01 UTC
+--- src/tds/tls.c.orig	2021-08-31 09:00:01 UTC
 +++ src/tds/tls.c
-@@ -50,6 +50,10 @@
+@@ -53,6 +53,10 @@
  #include <sys/socket.h>
  #endif
  
@@ -9,9 +9,18 @@
 +#endif
 +
  #include <freetds/tds.h>
- #include <freetds/string.h>
+ #include <freetds/utils/string.h>
  #include <freetds/tls.h>
-@@ -72,6 +76,15 @@
+@@ -63,7 +67,7 @@
+ 
+ /**
+  * \addtogroup network
+- * @{ 
++ * @{
+  */
+ 
+ #if defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
+@@ -75,6 +79,15 @@
  #define SSL_PTR ptr
  #else
  
@@ -25,5 +34,56 @@
 +#endif
 +
  /* some compatibility layer */
- #if OPENSSL_VERSION_NUMBER < 0x1010000FL
+ #if !HAVE_BIO_GET_DATA
  static inline void
+@@ -115,7 +128,7 @@ tds_pull_func_login(SSL_PULL_ARGS)
+ 	int have;
+ 
+ 	tdsdump_log(TDS_DBG_FUNC, "in tds_pull_func_login\n");
+-	
++
+ 	/* here we are initializing (crypted inside TDS packets) */
+ 
+ 	/* if we have some data send it */
+@@ -450,7 +463,7 @@ tds_ssl_init(TDSSOCKET *tds)
+ 	const char *tls_msg;
+ 
+ 	xcred = NULL;
+-	session = NULL;	
++	session = NULL;
+ 	tls_msg = "initializing tls";
+ 
+ 	if (!tls_initialized) {
+@@ -826,18 +839,25 @@ check_name_match(ASN1_STRING *name, const char *hostna
+ static int
+ check_name_match(ASN1_STRING *name, const char *hostname)
+ {
+-	char *name_utf8 = NULL;
++	char *name_utf8 = NULL, *tmp_name;
+ 	int ret, name_len;
+ 
+ 	name_len = ASN1_STRING_to_UTF8((unsigned char **) &name_utf8, name);
+ 	if (name_len < 0)
+ 		return 0;
+ 
++    tmp_name = tds_strndup(name_utf8, name_len);
++    OPENSSL_free(name_utf8);
++    if (!tmp_name)
++        return 0;
++
++    name_utf8 = tmp_name;
++
+ 	tdsdump_log(TDS_DBG_INFO1, "Got name %s\n", name_utf8);
+ 	ret = 0;
+ 	if (strlen(name_utf8) == name_len && check_wildcard(name_utf8, hostname))
+ 		ret = 1;
+-	OPENSSL_free(name_utf8);
++	free(name_utf8);
+ 	return ret;
+ }
+ 
+@@ -1095,4 +1115,3 @@ tds_ssl_deinit(TDSCONNECTION *conn)
+ 
+ #endif
+ /** @} */
+-