From: Bernd Edlinger Date: Mon, 20 Mar 2017 16:29:28 +0000 (+0100) Subject: Fix the parameter types of the CRYPTO_EX_dup function type. X-Git-Tag: openssl-3.0.0-alpha3~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=712e8debb5b2238450b303acb5f24298382c63a5;p=thirdparty%2Fopenssl.git Fix the parameter types of the CRYPTO_EX_dup function type. This fixes a strict aliasing issue in ui_dup_method_data. The parameter type of CRYPTO_EX_dup's from_d parameter is in fact void **, since it points to a pointer. This function is rarely used, therefore fix the param type although that may be considered an API breaking change. Reviewed-by: Richard Levitte (Merged from https://github.com/openssl/openssl/pull/2986) --- diff --git a/crypto/ex_data.c b/crypto/ex_data.c index 6200d05529a..80a136164ad 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c @@ -96,7 +96,7 @@ static void dummy_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, } static int dummy_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, - void *from_d, int idx, + void **from_d, int idx, long argl, void *argp) { return 1; diff --git a/crypto/ui/ui_util.c b/crypto/ui/ui_util.c index f64780a6a2a..6ca5706ea50 100644 --- a/crypto/ui/ui_util.c +++ b/crypto/ui/ui_util.c @@ -71,9 +71,8 @@ static void ui_new_method_data(void *parent, void *ptr, CRYPTO_EX_DATA *ad, } static int ui_dup_method_data(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, - void *from_d, int idx, long argl, void *argp) + void **pptr, int idx, long argl, void *argp) { - void **pptr = (void **)from_d; if (*pptr != NULL) *pptr = OPENSSL_memdup(*pptr, sizeof(struct pem_password_cb_data)); return 1; diff --git a/doc/man3/CRYPTO_get_ex_new_index.pod b/doc/man3/CRYPTO_get_ex_new_index.pod index e569a3d500f..fcedd0ec882 100644 --- a/doc/man3/CRYPTO_get_ex_new_index.pod +++ b/doc/man3/CRYPTO_get_ex_new_index.pod @@ -23,7 +23,7 @@ CRYPTO_free_ex_data, CRYPTO_new_ex_data typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp); typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, - void *from_d, int idx, long argl, void *argp); + void **from_d, int idx, long argl, void *argp); int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) @@ -140,10 +140,8 @@ dup_func() is called when a structure is being copied. This is only done for B, B, B objects and B chains via BIO_dup_chain(). The B and B parameters are pointers to the destination and source B structures, -respectively. The B parameter needs to be cast to a B -as the API has currently the wrong signature; that will be changed in a -future version. The B<*pptr> is a pointer to the source exdata. -When the dup_func() returns, the value in B<*pptr> is copied to the +respectively. The B<*from_d> parameter is a pointer to the source exdata. +When the dup_func() returns, the value in B<*from_d> is copied to the destination ex_data. If the pointer contained in B<*pptr> is not modified by the dup_func(), then both B and B will point to the same data. The B, B and B parameters are as described for the other @@ -165,6 +163,8 @@ dup_func() should return 0 for failure and 1 for success. =head1 HISTORY CRYPTO_alloc_ex_data() was added in OpenSSL 3.0. +The signature of the dup_func() callback was changed in OpenSSL 3.0 to use the +type B for B. Previously this parameter was of type B. =head1 COPYRIGHT diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h index 3cca316cd43..58965de0e8f 100644 --- a/include/openssl/crypto.h +++ b/include/openssl/crypto.h @@ -201,7 +201,7 @@ typedef void CRYPTO_EX_new (void *parent, void *ptr, CRYPTO_EX_DATA *ad, typedef void CRYPTO_EX_free (void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp); typedef int CRYPTO_EX_dup (CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, - void *from_d, int idx, long argl, void *argp); + void **from_d, int idx, long argl, void *argp); __owur int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, diff --git a/test/exdatatest.c b/test/exdatatest.c index 3ce6d33c1c8..2e92c328fd8 100644 --- a/test/exdatatest.c +++ b/test/exdatatest.c @@ -37,7 +37,7 @@ static void exnew(void *parent, void *ptr, CRYPTO_EX_DATA *ad, } static int exdup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, - void *from_d, int idx, long argl, void *argp) + void **from_d, int idx, long argl, void *argp) { if (!TEST_int_eq(idx, saved_idx) || !TEST_long_eq(argl, saved_argl) @@ -87,7 +87,7 @@ static void exnew2(void *parent, void *ptr, CRYPTO_EX_DATA *ad, } static int exdup2(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, - void *from_d, int idx, long argl, void *argp) + void **from_d, int idx, long argl, void *argp) { MYOBJ_EX_DATA **update_ex_data = (MYOBJ_EX_DATA**)from_d; MYOBJ_EX_DATA *ex_data = NULL;