Commit bbb5e928 authored by Mingtao Yang's avatar Mingtao Yang Committed by Facebook GitHub Bot

OpenSSLPtrTypes: Fix build with OpenSSL 3

Summary:
The history of `sk_*_free` and `sk_*_pop_free`:

* OpenSSL 1.0.2 - These were macros
* OpenSSL 1.1.0 - These changed to static inline functions
* OpenSSL 1.1.1 - These remained as static inline functions (for ABI compatibility with OpenSSL 1.1.0)
* OpenSSL 3.0.0 - These changed to macros.

Give up on trying to use the public interface for deleting `STACK_OF(T)`. This diff switches the implementation
to just invoke the underlying `OPENSSL_sk_free` and `OPENSSL_sk_pop_free`.

If a future version of OpenSSL changes the implementation such that `STACK_OF(T)` is not simply an alias of `OPENSSL_STACK`, we'll deal with it then.

Reviewed By: yfeldblum

Differential Revision: D33071607

fbshipit-source-id: ef37c984a120652c5224410cbafa634d4dc763d1
parent 43ba86e2
......@@ -146,39 +146,34 @@ FOLLY_SSL_DETAIL_DEFINE_PTR_TYPE(SSLSession, SSL_SESSION, SSL_SESSION_free);
// the appropriate destructor:
// * OwningStackOf* -> Invokes sk_T_free
// * BorrowingStackOf* -> Invokes sk_T_pop_free
//
// IMPLEMENTATION NOTES:
// * While the _current_ implementation of OpenSSL's STACK_OF APIs utilize
// type erased OPENSSL_sk_* APIs, this is technically an implementation
// detail. It is tempting to simply create a template type that invokes
// the appropriate type casting and OPENSSL_sk_* invocations, but we must
// avoid copying implementation details for how the sk_* generated
// user-facing APIs are implemented.
// * In other words, our own macro implementation below *must not* use
// OPENSSL_sk_* APIs. They *must* only use the corresponding sk_T_free,
// sk_T_pop_free user APIs (i.e. those that can be found in OpenSSL
// documentation).
#if FOLLY_OPENSSL_PREREQ(1, 1, 0)
namespace detail {
template <
class StackType,
class ElementType,
void (*OwningStackDestructor)(StackType*, void (*)(ElementType*)),
void (*ElementDestructor)(ElementType*)>
struct OpenSSLOwnedStackDeleter {
void operator()(StackType* stack) const {
OwningStackDestructor(stack, ElementDestructor);
OPENSSL_sk_pop_free(
reinterpret_cast<OPENSSL_STACK*>(stack),
reinterpret_cast<OPENSSL_sk_freefunc>(ElementDestructor));
}
};
template <class StackType>
struct OpenSSLBorrowedStackDestructor {
void operator()(StackType* stack) {
OPENSSL_sk_free(reinterpret_cast<OPENSSL_STACK*>(stack));
}
};
} // namespace detail
#if FOLLY_OPENSSL_PREREQ(1, 1, 0)
#define FOLLY_SSL_DETAIL_OWNING_STACK_DESTRUCTOR(T) \
::folly::ssl::detail:: \
OpenSSLOwnedStackDeleter<STACK_OF(T), T, sk_##T##_pop_free, T##_free>
::folly::ssl::detail::OpenSSLOwnedStackDeleter<STACK_OF(T), T, T##_free>
#define FOLLY_SSL_DETAIL_BORROWING_STACK_DESTRUCTOR(T) \
::folly::static_function_deleter<STACK_OF(T), &sk_##T##_free>
::folly::ssl::detail::OpenSSLBorrowedStackDestructor<STACK_OF(T)>
#else
namespace detail {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment