Skip to content

Commit

Permalink
Pass functions with correct signatures to the evp_generic_fetch_xxx m…
Browse files Browse the repository at this point in the history
…ethods

UBSan complains about functions being called with incorrect signatures.
Relates to openssl#22896

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#26318)
  • Loading branch information
fwh-dc authored and t8m committed Jan 7, 2025
1 parent 0f665e8 commit 3ffa64c
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 34 deletions.
14 changes: 12 additions & 2 deletions crypto/encode_decode/decoder_meth.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
*/
#define NAME_SEPARATOR ':'

static void ossl_decoder_free(void *data)
{
OSSL_DECODER_free(data);
}

static int ossl_decoder_up_ref(void *data)
{
return OSSL_DECODER_up_ref(data);
}

/* Simple method structure constructor and destructor */
static OSSL_DECODER *ossl_decoder_new(void)
{
Expand Down Expand Up @@ -191,8 +201,8 @@ static int put_decoder_in_store(void *store, void *method,
return 0;

return ossl_method_store_add(store, prov, id, propdef, method,
(int (*)(void *))OSSL_DECODER_up_ref,
(void (*)(void *))OSSL_DECODER_free);
ossl_decoder_up_ref,
ossl_decoder_free);
}

/* Create and populate a decoder method */
Expand Down
14 changes: 12 additions & 2 deletions crypto/encode_decode/encoder_meth.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
*/
#define NAME_SEPARATOR ':'

static void ossl_encoder_free(void *data)
{
OSSL_ENCODER_free(data);
}

static int ossl_encoder_up_ref(void *data)
{
return OSSL_ENCODER_up_ref(data);
}

/* Simple method structure constructor and destructor */
static OSSL_ENCODER *ossl_encoder_new(void)
{
Expand Down Expand Up @@ -191,8 +201,8 @@ static int put_encoder_in_store(void *store, void *method,
return 0;

return ossl_method_store_add(store, prov, id, propdef, method,
(int (*)(void *))OSSL_ENCODER_up_ref,
(void (*)(void *))OSSL_ENCODER_free);
ossl_encoder_up_ref,
ossl_encoder_free);
}

/* Create and populate a encoder method */
Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/asymcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_asym_cipher_free(void *data)
{
EVP_ASYM_CIPHER_free(data);
}

static int evp_asym_cipher_up_ref(void *data)
{
return EVP_ASYM_CIPHER_up_ref(data);
}

static int evp_pkey_asym_cipher_init(EVP_PKEY_CTX *ctx, int operation,
const OSSL_PARAM params[])
{
Expand Down Expand Up @@ -484,8 +494,8 @@ EVP_ASYM_CIPHER *EVP_ASYM_CIPHER_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
{
return evp_generic_fetch(ctx, OSSL_OP_ASYM_CIPHER, algorithm, properties,
evp_asym_cipher_from_algorithm,
(int (*)(void *))EVP_ASYM_CIPHER_up_ref,
(void (*)(void *))EVP_ASYM_CIPHER_free);
evp_asym_cipher_up_ref,
evp_asym_cipher_free);
}

EVP_ASYM_CIPHER *evp_asym_cipher_fetch_from_prov(OSSL_PROVIDER *prov,
Expand All @@ -495,8 +505,8 @@ EVP_ASYM_CIPHER *evp_asym_cipher_fetch_from_prov(OSSL_PROVIDER *prov,
return evp_generic_fetch_from_prov(prov, OSSL_OP_ASYM_CIPHER,
algorithm, properties,
evp_asym_cipher_from_algorithm,
(int (*)(void *))EVP_ASYM_CIPHER_up_ref,
(void (*)(void *))EVP_ASYM_CIPHER_free);
evp_asym_cipher_up_ref,
evp_asym_cipher_free);
}

int EVP_ASYM_CIPHER_is_a(const EVP_ASYM_CIPHER *cipher, const char *name)
Expand Down Expand Up @@ -527,8 +537,8 @@ void EVP_ASYM_CIPHER_do_all_provided(OSSL_LIB_CTX *libctx,
evp_generic_do_all(libctx, OSSL_OP_ASYM_CIPHER,
(void (*)(void *, void *))fn, arg,
evp_asym_cipher_from_algorithm,
(int (*)(void *))EVP_ASYM_CIPHER_up_ref,
(void (*)(void *))EVP_ASYM_CIPHER_free);
evp_asym_cipher_up_ref,
evp_asym_cipher_free);
}


Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_keyexch_free(void *data)
{
EVP_KEYEXCH_free(data);
}

static int evp_keyexch_up_ref(void *data)
{
return EVP_KEYEXCH_up_ref(data);
}

static EVP_KEYEXCH *evp_keyexch_new(OSSL_PROVIDER *prov)
{
EVP_KEYEXCH *exchange = OPENSSL_zalloc(sizeof(EVP_KEYEXCH));
Expand Down Expand Up @@ -172,8 +182,8 @@ EVP_KEYEXCH *EVP_KEYEXCH_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
{
return evp_generic_fetch(ctx, OSSL_OP_KEYEXCH, algorithm, properties,
evp_keyexch_from_algorithm,
(int (*)(void *))EVP_KEYEXCH_up_ref,
(void (*)(void *))EVP_KEYEXCH_free);
evp_keyexch_up_ref,
evp_keyexch_free);
}

EVP_KEYEXCH *evp_keyexch_fetch_from_prov(OSSL_PROVIDER *prov,
Expand All @@ -183,8 +193,8 @@ EVP_KEYEXCH *evp_keyexch_fetch_from_prov(OSSL_PROVIDER *prov,
return evp_generic_fetch_from_prov(prov, OSSL_OP_KEYEXCH,
algorithm, properties,
evp_keyexch_from_algorithm,
(int (*)(void *))EVP_KEYEXCH_up_ref,
(void (*)(void *))EVP_KEYEXCH_free);
evp_keyexch_up_ref,
evp_keyexch_free);
}

int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx)
Expand Down Expand Up @@ -562,8 +572,8 @@ void EVP_KEYEXCH_do_all_provided(OSSL_LIB_CTX *libctx,
evp_generic_do_all(libctx, OSSL_OP_KEYEXCH,
(void (*)(void *, void *))fn, arg,
evp_keyexch_from_algorithm,
(int (*)(void *))EVP_KEYEXCH_up_ref,
(void (*)(void *))EVP_KEYEXCH_free);
evp_keyexch_up_ref,
evp_keyexch_free);
}

int EVP_KEYEXCH_names_do_all(const EVP_KEYEXCH *keyexch,
Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/kem.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_kem_free(void *data)
{
EVP_KEM_free(data);
}

static int evp_kem_up_ref(void *data)
{
return EVP_KEM_up_ref(data);
}

static int evp_kem_init(EVP_PKEY_CTX *ctx, int operation,
const OSSL_PARAM params[], EVP_PKEY *authkey)
{
Expand Down Expand Up @@ -452,17 +462,17 @@ EVP_KEM *EVP_KEM_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
{
return evp_generic_fetch(ctx, OSSL_OP_KEM, algorithm, properties,
evp_kem_from_algorithm,
(int (*)(void *))EVP_KEM_up_ref,
(void (*)(void *))EVP_KEM_free);
evp_kem_up_ref,
evp_kem_free);
}

EVP_KEM *evp_kem_fetch_from_prov(OSSL_PROVIDER *prov, const char *algorithm,
const char *properties)
{
return evp_generic_fetch_from_prov(prov, OSSL_OP_KEM, algorithm, properties,
evp_kem_from_algorithm,
(int (*)(void *))EVP_KEM_up_ref,
(void (*)(void *))EVP_KEM_free);
evp_kem_up_ref,
evp_kem_free);
}

int EVP_KEM_is_a(const EVP_KEM *kem, const char *name)
Expand Down Expand Up @@ -491,8 +501,8 @@ void EVP_KEM_do_all_provided(OSSL_LIB_CTX *libctx,
{
evp_generic_do_all(libctx, OSSL_OP_KEM, (void (*)(void *, void *))fn, arg,
evp_kem_from_algorithm,
(int (*)(void *))EVP_KEM_up_ref,
(void (*)(void *))EVP_KEM_free);
evp_kem_up_ref,
evp_kem_free);
}

int EVP_KEM_names_do_all(const EVP_KEM *kem,
Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/keymgmt_meth.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_keymgmt_free(void *data)
{
EVP_KEYMGMT_free(data);
}

static int evp_keymgmt_up_ref(void *data)
{
return EVP_KEYMGMT_up_ref(data);
}

static void *keymgmt_new(void)
{
EVP_KEYMGMT *keymgmt = NULL;
Expand Down Expand Up @@ -268,17 +278,17 @@ EVP_KEYMGMT *evp_keymgmt_fetch_from_prov(OSSL_PROVIDER *prov,
return evp_generic_fetch_from_prov(prov, OSSL_OP_KEYMGMT,
name, properties,
keymgmt_from_algorithm,
(int (*)(void *))EVP_KEYMGMT_up_ref,
(void (*)(void *))EVP_KEYMGMT_free);
evp_keymgmt_up_ref,
evp_keymgmt_free);
}

EVP_KEYMGMT *EVP_KEYMGMT_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
const char *properties)
{
return evp_generic_fetch(ctx, OSSL_OP_KEYMGMT, algorithm, properties,
keymgmt_from_algorithm,
(int (*)(void *))EVP_KEYMGMT_up_ref,
(void (*)(void *))EVP_KEYMGMT_free);
evp_keymgmt_up_ref,
evp_keymgmt_free);
}

int EVP_KEYMGMT_up_ref(EVP_KEYMGMT *keymgmt)
Expand Down Expand Up @@ -343,8 +353,8 @@ void EVP_KEYMGMT_do_all_provided(OSSL_LIB_CTX *libctx,
evp_generic_do_all(libctx, OSSL_OP_KEYMGMT,
(void (*)(void *, void *))fn, arg,
keymgmt_from_algorithm,
(int (*)(void *))EVP_KEYMGMT_up_ref,
(void (*)(void *))EVP_KEYMGMT_free);
evp_keymgmt_up_ref,
evp_keymgmt_free);
}

int EVP_KEYMGMT_names_do_all(const EVP_KEYMGMT *keymgmt,
Expand Down
22 changes: 16 additions & 6 deletions crypto/evp/signature.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@
#include "crypto/evp.h"
#include "evp_local.h"

static void evp_signature_free(void *data)
{
EVP_SIGNATURE_free(data);
}

static int evp_signature_up_ref(void *data)
{
return EVP_SIGNATURE_up_ref(data);
}

static EVP_SIGNATURE *evp_signature_new(OSSL_PROVIDER *prov)
{
EVP_SIGNATURE *signature = OPENSSL_zalloc(sizeof(EVP_SIGNATURE));
Expand Down Expand Up @@ -404,8 +414,8 @@ EVP_SIGNATURE *EVP_SIGNATURE_fetch(OSSL_LIB_CTX *ctx, const char *algorithm,
{
return evp_generic_fetch(ctx, OSSL_OP_SIGNATURE, algorithm, properties,
evp_signature_from_algorithm,
(int (*)(void *))EVP_SIGNATURE_up_ref,
(void (*)(void *))EVP_SIGNATURE_free);
evp_signature_up_ref,
evp_signature_free);
}

EVP_SIGNATURE *evp_signature_fetch_from_prov(OSSL_PROVIDER *prov,
Expand All @@ -415,8 +425,8 @@ EVP_SIGNATURE *evp_signature_fetch_from_prov(OSSL_PROVIDER *prov,
return evp_generic_fetch_from_prov(prov, OSSL_OP_SIGNATURE,
algorithm, properties,
evp_signature_from_algorithm,
(int (*)(void *))EVP_SIGNATURE_up_ref,
(void (*)(void *))EVP_SIGNATURE_free);
evp_signature_up_ref,
evp_signature_free);
}

int EVP_SIGNATURE_is_a(const EVP_SIGNATURE *signature, const char *name)
Expand Down Expand Up @@ -448,8 +458,8 @@ void EVP_SIGNATURE_do_all_provided(OSSL_LIB_CTX *libctx,
evp_generic_do_all(libctx, OSSL_OP_SIGNATURE,
(void (*)(void *, void *))fn, arg,
evp_signature_from_algorithm,
(int (*)(void *))EVP_SIGNATURE_up_ref,
(void (*)(void *))EVP_SIGNATURE_free);
evp_signature_up_ref,
evp_signature_free);
}


Expand Down

0 comments on commit 3ffa64c

Please sign in to comment.