From: tb Date: Fri, 3 Dec 2021 14:18:06 +0000 (+0000) Subject: Fix EVP_PKEY_{asn1,meth}_copy once and for all X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a539240bb8a77526e19bb1a44aaeff58999fbbdb;p=openbsd Fix EVP_PKEY_{asn1,meth}_copy once and for all It is very easy to forget to copy over newly added methods. Everyone working in this corner has run into this. Instead, preserve what needs preserving and use a struct copy, so all methods get copied from src to dest. tweak/ok jsing --- diff --git a/lib/libcrypto/asn1/ameth_lib.c b/lib/libcrypto/asn1/ameth_lib.c index 8be82060ef5..545ba8f1a17 100644 --- a/lib/libcrypto/asn1/ameth_lib.c +++ b/lib/libcrypto/asn1/ameth_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ameth_lib.c,v 1.21 2019/11/02 16:06:25 inoguchi Exp $ */ +/* $OpenBSD: ameth_lib.c,v 1.22 2021/12/03 14:18:06 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -340,34 +340,21 @@ EVP_PKEY_asn1_new(int id, int flags, const char *pem_str, const char *info) void EVP_PKEY_asn1_copy(EVP_PKEY_ASN1_METHOD *dst, const EVP_PKEY_ASN1_METHOD *src) { - dst->pub_decode = src->pub_decode; - dst->pub_encode = src->pub_encode; - dst->pub_cmp = src->pub_cmp; - dst->pub_print = src->pub_print; - - dst->priv_decode = src->priv_decode; - dst->priv_encode = src->priv_encode; - dst->priv_print = src->priv_print; - - dst->old_priv_encode = src->old_priv_encode; - dst->old_priv_decode = src->old_priv_decode; - - dst->pkey_size = src->pkey_size; - dst->pkey_bits = src->pkey_bits; - - dst->param_decode = src->param_decode; - dst->param_encode = src->param_encode; - dst->param_missing = src->param_missing; - dst->param_copy = src->param_copy; - dst->param_cmp = src->param_cmp; - dst->param_print = src->param_print; - dst->sig_print = src->sig_print; - - dst->pkey_free = src->pkey_free; - dst->pkey_ctrl = src->pkey_ctrl; - - dst->item_sign = src->item_sign; - dst->item_verify = src->item_verify; + EVP_PKEY_ASN1_METHOD preserve; + + preserve.pkey_id = dst->pkey_id; + preserve.pkey_base_id = dst->pkey_base_id; + preserve.pkey_flags = dst->pkey_flags; + preserve.pem_str = dst->pem_str; + preserve.info = dst->info; + + *dst = *src; + + dst->pkey_id = preserve.pkey_id; + dst->pkey_base_id = preserve.pkey_base_id; + dst->pkey_flags = preserve.pkey_flags; + dst->pem_str = preserve.pem_str; + dst->info = preserve.info; } void diff --git a/lib/libcrypto/evp/pmeth_lib.c b/lib/libcrypto/evp/pmeth_lib.c index 36bfe8d9fc8..359e57d74c5 100644 --- a/lib/libcrypto/evp/pmeth_lib.c +++ b/lib/libcrypto/evp/pmeth_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmeth_lib.c,v 1.16 2019/11/01 15:08:57 jsing Exp $ */ +/* $OpenBSD: pmeth_lib.c,v 1.17 2021/12/03 14:18:06 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -272,42 +272,15 @@ EVP_PKEY_meth_get0_info(int *ppkey_id, int *pflags, const EVP_PKEY_METHOD *meth) void EVP_PKEY_meth_copy(EVP_PKEY_METHOD *dst, const EVP_PKEY_METHOD *src) { - dst->init = src->init; - dst->copy = src->copy; - dst->cleanup = src->cleanup; + EVP_PKEY_METHOD preserve; - dst->paramgen_init = src->paramgen_init; - dst->paramgen = src->paramgen; + preserve.pkey_id = dst->pkey_id; + preserve.flags = dst->flags; - dst->keygen_init = src->keygen_init; - dst->keygen = src->keygen; + *dst = *src; - dst->sign_init = src->sign_init; - dst->sign = src->sign; - - dst->verify_init = src->verify_init; - dst->verify = src->verify; - - dst->verify_recover_init = src->verify_recover_init; - dst->verify_recover = src->verify_recover; - - dst->signctx_init = src->signctx_init; - dst->signctx = src->signctx; - - dst->verifyctx_init = src->verifyctx_init; - dst->verifyctx = src->verifyctx; - - dst->encrypt_init = src->encrypt_init; - dst->encrypt = src->encrypt; - - dst->decrypt_init = src->decrypt_init; - dst->decrypt = src->decrypt; - - dst->derive_init = src->derive_init; - dst->derive = src->derive; - - dst->ctrl = src->ctrl; - dst->ctrl_str = src->ctrl_str; + dst->pkey_id = preserve.pkey_id; + dst->flags = preserve.flags; } void