diff options
author | David Benjamin <davidben@chromium.org> | 2015-06-30 06:36:17 +0300 |
---|---|---|
committer | Adam Langley <agl@google.com> | 2015-07-20 19:56:34 +0300 |
commit | aa58513f404f1d939fd2f6081e24c4c6b0027cb0 (patch) | |
tree | 5036d9ba577f4825420240e1bdd6864857875394 /crypto/internal.h | |
parent | 31ac9aae51b8ce69afd318149d8fea27cd16955c (diff) |
Reserve ex_data index zero for app_data.
In the ancient times, before ex_data and OpenSSL, SSLeay supported a
single app_data slot in various types. Later app_data begat ex_data, and
app_data was replaced by compatibility macros to ex_data index zero.
Today, app_data is still in use, but ex_data never reserved index zero
for app_data. This causes some danger where, if the first ex_data
registration did not use NULL callbacks, the registration's callbacks
would collide with app_data.
Instead, add an option to the types with app_data to reserve index zero.
Also switch SSL_get_ex_data_X509_STORE_CTX_idx to always return zero
rather than allocate a new one. It used to be that you used
X509_STORE_CTX_get_app_data. I only found one consumer that we probably
don't care about, but, to be safe and since it's easy, go with the
conservative option. (Although SSL_get_ex_data_X509_STORE_CTX_idx wasn't
guaranteed to alias app_data, in practice it always did. No consumer
ever calls X509_STORE_CTX_get_ex_new_index.)
Change-Id: Ie75b279d60aefd003ffef103f99021c5d696a5e9
Reviewed-on: https://boringssl-review.googlesource.com/5313
Reviewed-by: Adam Langley <agl@google.com>
Diffstat (limited to 'crypto/internal.h')
-rw-r--r-- | crypto/internal.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/crypto/internal.h b/crypto/internal.h index 59eddd0e..a502d20e 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -493,9 +493,14 @@ typedef struct crypto_ex_data_func_st CRYPTO_EX_DATA_FUNCS; typedef struct { struct CRYPTO_STATIC_MUTEX lock; STACK_OF(CRYPTO_EX_DATA_FUNCS) *meth; + /* num_reserved is one if the ex_data index zero is reserved for legacy + * |TYPE_get_app_data| functions. */ + uint8_t num_reserved; } CRYPTO_EX_DATA_CLASS; -#define CRYPTO_EX_DATA_CLASS_INIT {CRYPTO_STATIC_MUTEX_INIT, NULL} +#define CRYPTO_EX_DATA_CLASS_INIT {CRYPTO_STATIC_MUTEX_INIT, NULL, 0} +#define CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA \ + {CRYPTO_STATIC_MUTEX_INIT, NULL, 1} /* CRYPTO_get_ex_new_index allocates a new index for |ex_data_class| and writes * it to |*out_index|. Each class of object should provide a wrapper function |