From 33877b2c55be2d9a4deaf56c709a7943dd00b62c Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 17 Jan 2020 20:50:09 +0100 Subject: address fixme, fix use-after-free in testing traits --- src/lib/exchange_api_handle.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/lib/exchange_api_handle.c') diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index c3a0598f..d7f56bc8 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -2127,6 +2127,43 @@ TALER_EXCHANGE_get_denomination_key (const struct TALER_EXCHANGE_Keys *keys, } +/** + * Create a copy of a denomination public key. + * + * @param key key to copy + * @returns a copy, must be freed with #TALER_EXCHANGE_destroy_denomination_key + */ +struct TALER_EXCHANGE_DenomPublicKey * +TALER_EXCHANGE_copy_denomination_key (const struct + TALER_EXCHANGE_DenomPublicKey *key) +{ + struct TALER_EXCHANGE_DenomPublicKey *copy; + + copy = GNUNET_new (struct TALER_EXCHANGE_DenomPublicKey); + *copy = *key; + copy->key.rsa_public_key = GNUNET_CRYPTO_rsa_public_key_dup ( + key->key.rsa_public_key); + + return copy; +} + + +/** + * Destroy a denomination public key. + * Should only be called with keys created by #TALER_EXCHANGE_copy_denomination_key. + * + * @param key key to destroy. + */ +void +TALER_EXCHANGE_destroy_denomination_key (struct + TALER_EXCHANGE_DenomPublicKey *key) +{ + GNUNET_CRYPTO_rsa_public_key_free (key->key.rsa_public_key);; + key->key.rsa_public_key = NULL; + GNUNET_free (key); +} + + /** * Obtain the denomination key details from the exchange. * -- cgit v1.2.3