/*
* Return the EX_CALLBACKS from the |ex_data| array that corresponds to
* a given class. On success, *holds the lock.*
+ * The |global| parameter is assumed to be non null (checked by the caller).
*/
-static EX_CALLBACKS *get_and_lock(OPENSSL_CTX *ctx, int class_index)
+static EX_CALLBACKS *get_and_lock(OSSL_EX_DATA_GLOBAL *global, int class_index)
{
EX_CALLBACKS *ip;
- OSSL_EX_DATA_GLOBAL *global = NULL;
if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) {
CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_PASSED_INVALID_ARGUMENT);
return NULL;
}
- global = openssl_ctx_get_ex_data_global(ctx);
- if (global == NULL || global->ex_data_lock == NULL) {
+ if (global->ex_data_lock == NULL) {
/*
* If we get here, someone (who?) cleaned up the lock, so just
* treat it as an error.
if (global == NULL)
return 0;
- ip = get_and_lock(ctx, class_index);
+ ip = get_and_lock(global, class_index);
if (ip == NULL)
return 0;
+
if (idx < 0 || idx >= sk_EX_CALLBACK_num(ip->meth))
goto err;
a = sk_EX_CALLBACK_value(ip->meth, idx);
if (global == NULL)
return -1;
- ip = get_and_lock(ctx, class_index);
+ ip = get_and_lock(global, class_index);
if (ip == NULL)
return -1;
if (global == NULL)
return 0;
- ip = get_and_lock(ctx, class_index);
+ ip = get_and_lock(global, class_index);
if (ip == NULL)
return 0;
ad->ctx = ctx;
ad->sk = NULL;
-
mx = sk_EX_CALLBACK_num(ip->meth);
if (mx > 0) {
if (mx < (int)OSSL_NELEM(stack))
EX_CALLBACK **storage = NULL;
EX_CALLBACKS *ip;
int toret = 0;
- OSSL_EX_DATA_GLOBAL *global = openssl_ctx_get_ex_data_global(from->ctx);
-
- if (global == NULL)
- return 0;
+ OSSL_EX_DATA_GLOBAL *global;
to->ctx = from->ctx;
if (from->sk == NULL)
/* Nothing to copy over */
return 1;
- if ((ip = get_and_lock(from->ctx, class_index)) == NULL)
+
+ global = openssl_ctx_get_ex_data_global(from->ctx);
+ if (global == NULL)
+ return 0;
+
+ ip = get_and_lock(global, class_index);
+ if (ip == NULL)
return 0;
mx = sk_EX_CALLBACK_num(ip->meth);
EX_CALLBACK *f;
EX_CALLBACK *stack[10];
EX_CALLBACK **storage = NULL;
- OSSL_EX_DATA_GLOBAL *global;
+ OSSL_EX_DATA_GLOBAL *global = openssl_ctx_get_ex_data_global(ad->ctx);
- if ((ip = get_and_lock(ad->ctx, class_index)) == NULL)
- goto err;
- global = openssl_ctx_get_ex_data_global(ad->ctx);
if (global == NULL)
goto err;
+ ip = get_and_lock(global, class_index);
+ if (ip == NULL)
+ goto err;
+
mx = sk_EX_CALLBACK_num(ip->meth);
if (mx > 0) {
if (mx < (int)OSSL_NELEM(stack))
EX_CALLBACK *f;
EX_CALLBACKS *ip;
void *curval;
- OSSL_EX_DATA_GLOBAL *global = openssl_ctx_get_ex_data_global(ad->ctx);
-
- if (global == NULL)
- return 0;
+ OSSL_EX_DATA_GLOBAL *global;
curval = CRYPTO_get_ex_data(ad, idx);
-
/* Already there, no need to allocate */
if (curval != NULL)
return 1;
- ip = get_and_lock(ad->ctx, class_index);
+ global = openssl_ctx_get_ex_data_global(ad->ctx);
+ if (global == NULL)
+ return 0;
+
+ ip = get_and_lock(global, class_index);
if (ip == NULL)
return 0;
f = sk_EX_CALLBACK_value(ip->meth, idx);