]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix ubsan errors in OPENSSL_sk_pop_free
authorNeil Horman <nhorman@openssl.org>
Tue, 20 Jan 2026 19:49:57 +0000 (14:49 -0500)
committerNeil Horman <nhorman@openssl.org>
Tue, 27 Jan 2026 17:25:21 +0000 (12:25 -0500)
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ý <sashan@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Norbert Pocs <norbertp@openssl.org>
MergeDate: Tue Jan 27 17:25:34 2026
(Merged from https://github.com/openssl/openssl/pull/29690)

include/openssl/safestack.h.in
util/perl/OpenSSL/stackhash.pm

index 5d556e2061945ab0da77ded16f3fa7c72e300739..0e72de009eb54ba6d3b7256f06422611eff541b6 100644 (file)
@@ -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)                  \
     {                                                                                                                      \
index f9f5e9ca825940a3af7b8361a436577226f33356..0b8482e003cf63d64e2b9d0916c8bba1169ce6cc 100644 (file)
@@ -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))