From: Neil Horman Date: Tue, 20 Jan 2026 19:49:57 +0000 (-0500) Subject: Fix ubsan errors in OPENSSL_sk_pop_free X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ef3cd84b6a6f3d1dfc6b01e2768d14b4abf8e4e;p=thirdparty%2Fopenssl.git Fix ubsan errors in OPENSSL_sk_pop_free ubsan reports an error in the free callback function for OPENSSL_sk_pop_free. Need to add a thunking shim to cast the pointer data types to their proper types Fixes #29616 Reviewed-by: Saša Nedvědický Reviewed-by: Paul Dale Reviewed-by: Norbert Pocs MergeDate: Tue Jan 27 17:25:34 2026 (Merged from https://github.com/openssl/openssl/pull/29690) --- diff --git a/include/openssl/safestack.h.in b/include/openssl/safestack.h.in index 5d556e20619..0e72de009eb 100644 --- a/include/openssl/safestack.h.in +++ b/include/openssl/safestack.h.in @@ -99,7 +99,12 @@ extern "C" { } \ static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_null(void) \ { \ - return (STACK_OF(t1) *)OPENSSL_sk_new_null(); \ + OPENSSL_STACK *ret = OPENSSL_sk_new_null(); \ + OPENSSL_sk_freefunc_thunk f_thunk; \ + \ + f_thunk = (OPENSSL_sk_freefunc_thunk)sk_##t1##_freefunc_thunk; \ + \ + return (STACK_OF(t1) *)OPENSSL_sk_set_thunks(ret, f_thunk); \ } \ static ossl_unused ossl_inline STACK_OF(t1) *sk_##t1##_new_reserve(sk_##t1##_compfunc compare, int n) \ { \ diff --git a/util/perl/OpenSSL/stackhash.pm b/util/perl/OpenSSL/stackhash.pm index f9f5e9ca825..0b8482e003c 100644 --- a/util/perl/OpenSSL/stackhash.pm +++ b/util/perl/OpenSSL/stackhash.pm @@ -29,7 +29,7 @@ SKM_DEFINE_STACK_OF_INTERNAL(${nametype}, ${realtype}, ${plaintype}) #define sk_${nametype}_num(sk) OPENSSL_sk_num(ossl_check_const_${nametype}_sk_type(sk)) #define sk_${nametype}_value(sk, idx) ((${realtype} *)OPENSSL_sk_value(ossl_check_const_${nametype}_sk_type(sk), (idx))) #define sk_${nametype}_new(cmp) ((STACK_OF(${nametype}) *)OPENSSL_sk_new(ossl_check_${nametype}_compfunc_type(cmp))) -#define sk_${nametype}_new_null() ((STACK_OF(${nametype}) *)OPENSSL_sk_new_null()) +#define sk_${nametype}_new_null() ((STACK_OF(${nametype}) *)OPENSSL_sk_set_thunks(OPENSSL_sk_new_null(), sk_${nametype}_freefunc_thunk)) #define sk_${nametype}_new_reserve(cmp, n) ((STACK_OF(${nametype}) *)OPENSSL_sk_new_reserve(ossl_check_${nametype}_compfunc_type(cmp), (n))) #define sk_${nametype}_reserve(sk, n) OPENSSL_sk_reserve(ossl_check_${nametype}_sk_type(sk), (n)) #define sk_${nametype}_free(sk) OPENSSL_sk_free(ossl_check_${nametype}_sk_type(sk))