diff options
author | Richard Levitte <levitte@openssl.org> | 2019-02-08 16:46:28 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-02-16 00:29:20 +0100 |
commit | e17f5b6a6bae56175201a96feb8e855835865bb0 (patch) | |
tree | 466c1081cd49c6778ffcd8e222edd9bc067fb615 /crypto/ex_data.c | |
parent | fa1f03061037cbdac5369849a885c1191a2550d9 (diff) |
Add CRYPTO_alloc_ex_data()
This allows allocation of items at indexes that were created after the
CRYPTO_EX_DATA variable was initialized, using the exact same method
that was used then.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8225)
Diffstat (limited to 'crypto/ex_data.c')
-rw-r--r-- | crypto/ex_data.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crypto/ex_data.c b/crypto/ex_data.c index 33f43bf2e7..a728bfbbd3 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c @@ -363,6 +363,36 @@ void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) } /* + * Allocate a given CRYPTO_EX_DATA item using the class specific allocation + * function + */ +int CRYPTO_alloc_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad, + int idx) +{ + EX_CALLBACK *f; + EX_CALLBACKS *ip; + void *curval; + + curval = CRYPTO_get_ex_data(ad, idx); + + /* Already there, no need to allocate */ + if (curval != NULL) + return 1; + + ip = get_and_lock(class_index); + f = sk_EX_CALLBACK_value(ip->meth, idx); + CRYPTO_THREAD_unlock(ex_data_lock); + + /* + * This should end up calling CRYPTO_set_ex_data(), which allocates + * everything necessary to support placing the new data in the right spot. + */ + f->new_func(obj, curval, ad, idx, f->argl, f->argp); + + return 1; +} + +/* * For a given CRYPTO_EX_DATA variable, set the value corresponding to a * particular index in the class used by this variable */ |