From 099af5e395b843f86694005704111049f22e5d39 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Fri, 20 Jul 2018 15:10:06 +1000 Subject: src/openssl.c: Add SSL_CTX_up_ref shim for OpenSSL < 1.1.0 --- src/openssl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/openssl.c b/src/openssl.c index 102408e..c66c270 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -311,6 +311,10 @@ #define HAVE_SSL_CTX_SET1_PARAM (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,1,0)) #endif +#ifndef HAVE_SSL_CTX_UP_REF +#define HAVE_SSL_CTX_UP_REF (OPENSSL_PREREQ(1,1,0) || LIBRESSL_PREREQ(2,7,0)) +#endif + #ifndef HAVE_SSL_CTX_CERT_STORE #define HAVE_SSL_CTX_CERT_STORE (!OPENSSL_PREREQ(1,1,0)) #endif @@ -1853,6 +1857,18 @@ static int compat_SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm) { } /* compat_SSL_CTX_set1_param() */ #endif +#if !HAVE_SSL_CTX_UP_REF +#define SSL_CTX_up_ref(...) EXPAND( compat_SSL_CTX_up_ref(__VA_ARGS__) ) + +static int compat_SSL_CTX_up_ref(SSL_CTX *ctx) { + /* our caller should already have had a proper reference */ + if (CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX) < 2) + return 0; /* fail */ + + return 1; +} /* compat_SSL_CTX_up_ref() */ +#endif + #if !HAVE_STACK_OPENSSL_STRING_FUNCS #define sk_OPENSSL_STRING_num(s) sk_num(s) #define sk_OPENSSL_STRING_value(s, i) sk_value((s), (i)) -- cgit v1.2.3-59-g8ed1b