]> git.ipfire.org Git - thirdparty/openssl.git/commit
add a compare thunk function to the STACK of macros
authorNeil Horman <nhorman@openssl.org>
Wed, 14 Jan 2026 15:10:21 +0000 (10:10 -0500)
committerNeil Horman <nhorman@openssl.org>
Sat, 7 Feb 2026 18:11:08 +0000 (13:11 -0500)
commite94e75d23eb36e6d75aaa52c7efdbf273628381e
treef8bb0b0d98359de6b8f623880f43f1c9cb110c13
parent25a51c5cacbe7b1d1aadb3037a96bdfd09faaf45
add a compare thunk function to the STACK of macros

Now that ossl_bsearch is capable of using a thunking function, lets
create a thunking function to use for the STACK_OF macros.

The problem we're addressing is one that gives rise to ubsan issues.
clang-16 forward have a ubsan test that confirms that the target symbol
that we call through a pointer matches the type of the pointer itself.
for instance

int foo(void *a, void *b)
{
   ...
}

int (*fooptr)(char *ac, int *bc) = foo;

fooptr(&charval, &intval);

is strictly speaking in C undefined behavior (even though in normal
operation this works as expected).  Newer compilers are strict about
this however, as several security frameworks operate with an expectation
that this constraint is met.
See https://github.com/openssl/openssl/issues/22896#issuecomment-1837266357
for details.

So we need to create a thunking function.  The sole purpose of this
thunking function is to accept the "real" comparison function for the
STACK_OF macros, along with the two items to compare of the type that
they are passed as from the calling function, and do the convervsion of
both the comparison function and the data pointers to the types that the
real comparison function expects

So we:
1) Modify the DEFINE_STACK_OF macros to create this thunking function
2) Add an OPENSSL_sk_set_cmp_thunks api to set the comparison function
3) modify the requisite places in the stack code to use the thunking
   function when available

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
MergeDate: Sat Feb  7 18:11:14 2026
(Merged from https://github.com/openssl/openssl/pull/29640)
crypto/stack/stack.c
include/openssl/safestack.h.in
include/openssl/stack.h
util/libcrypto.num
util/perl/OpenSSL/stackhash.pm