[Bug 274494] databases/mariadb106: fix build with LibreSSL

From: <bugzilla-noreply_at_freebsd.org>
Date: Sun, 15 Oct 2023 19:12:58 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274494

--- Comment #2 from Ivan Rozhuk <rozhuk.im@gmail.com> ---
(In reply to Bernard Spil from comment #1)

Strange, it should not build with libressl.
I use my patch + workaround from:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273961


LibreSSL 3.7.3_1 includes are used, as far it have definition with 1 arg:
/usr/local/include/openssl/crypto.h:int CRYPTO_set_mem_functions(void
*(*m)(size_t), void *(*r)(void *, size_t), void (*f)(void *));

Base OpenSSL have definition with 3 args:
/usr/include/openssl/crypto.h:int CRYPTO_set_mem_functions(
        void *(*m) (size_t, const char *, int),
        void *(*r) (void *, size_t, const char *, int),
        void (*f) (void *, const char *, int));

Maria defines:
/* OpenSSL version specific definitions */
#if defined(OPENSSL_VERSION_NUMBER)

#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \
        !(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER <
0x30500000L)
#define HAVE_OPENSSL11 1

Next if HAVE_OPENSSL11 defined than it build code to call
CRYPTO_set_mem_functions().

So it is 100% that LibreSSL includes used.


If I do replace to
#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \
        !(defined(LIBRESSL_VERSION_NUMBER))
and HAVE_OPENSSL11 is undefined then another error happen:
...
FAILED: vio/CMakeFiles/vio.dir/viosslfactories.c.o 
/usr/local/libexec/ccache/cc -DHAVE_CONFIG_H -DHAVE_OPENSSL
-I/tmp/ports/usr/ports/databases/mariadb106-client/work/mariadb-10.6.15/include
-I/usr/local/include -O2 -pipe -O3 -pipe -funroll-loops -mretpoline
-fno-delete-null-pointer-checks  -fstack-protector-strong -isystem
/usr/local/include -fno-strict-aliasing 
-fdebug-prefix-map=/tmp/ports/usr/ports/databases/mariadb106-client/work/mariadb-10.6.15=.
-fstack-protector --param=ssp-buffer-size=4 -O2 -pipe -O3 -pipe -funroll-loops
-mretpoline -fno-delete-null-pointer-checks  -fstack-protector-strong -isystem
/usr/local/include -fno-strict-aliasing 
-fdebug-prefix-map=/tmp/ports/usr/ports/databases/mariadb106-client/work/mariadb-10.6.15=.
-DNDEBUG -D_FORTIFY_SOURCE=2 -DDBUG_OFF -std=gnu99   -I/usr/local/include
-isystem /usr/local/include -fPIC -MD -MT
vio/CMakeFiles/vio.dir/viosslfactories.c.o -MF
vio/CMakeFiles/vio.dir/viosslfactories.c.o.d -o
vio/CMakeFiles/vio.dir/viosslfactories.c.o -c
/tmp/ports/usr/ports/databases/mariadb106-client/work/mariadb-10.6.15/vio/viosslfactories.c
In file included from vio/viosslfactories.c:17:
In file included from vio/vio_priv.h:25:
In file included from include/my_sys.h:28:
include/m_ctype.h:47:23: warning: redefinition of typedef 'ulong' is a C11
feature [-Wtypedef-redefinition]
typedef unsigned long ulong;
                      ^
include/my_global.h:891:23: note: previous definition is here
typedef unsigned long   ulong;            /* Short for unsigned long */
                        ^
vio/viosslfactories.c:67:17: error: incomplete definition of type 'struct
dh_st'
            || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/ssl_compat.h:78:45: note: expanded from macro 'DH_set0_pqg'
#define DH_set0_pqg(D,P,Q,G)            ((D)->p= (P), (D)->g= (G))
                                         ~~~^
/usr/local/include/openssl/ossl_typ.h:132:16: note: forward declaration of
'struct dh_st'
typedef struct dh_st DH;
               ^
vio/viosslfactories.c:67:17: error: incomplete definition of type 'struct
dh_st'
            || !DH_set0_pqg(dh, dhp_bn, NULL, dhg_bn)) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/ssl_compat.h:78:58: note: expanded from macro 'DH_set0_pqg'
#define DH_set0_pqg(D,P,Q,G)            ((D)->p= (P), (D)->g= (G))
                                                      ~~~^
/usr/local/include/openssl/ossl_typ.h:132:16: note: forward declaration of
'struct dh_st'
typedef struct dh_st DH;
               ^
1 warning and 2 errors generated.
...



....
/*
  The check is only done for OpenSSL 1.1.x.
  It could run for OpenSSL 1.0.x but it doesn't make much sense
  and it hits this bug:
  https://bugs.launchpad.net/ubuntu/+source/openssl/+bug/1594748
*/

#ifndef HAVE_OPENSSL11
int check_openssl_compatibility()
{
  return 0;
}
#else
... here code that was fixed by attached patch...


check_openssl_compatibility() - always build by CMake, and called by runtime:
...
#ifdef HAVE_OPENSSL
  if (check_openssl_compatibility())
  {
    sql_print_error("Incompatible OpenSSL version. Cannot continue...");
    exit(1);
  }
#endif
...


Is it possible that you some how build without OpenSSL support or with WolfSSL
as cryptoengine?
(sorry for long and mess post, there is no formatting features)

-- 
You are receiving this mail because:
You are the assignee for the bug.