| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ex_data.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||
| 2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||
| 3 | * | - | ||||||||||||
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||
| 5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||
| 6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||
| 7 | * https://www.openssl.org/source/license.html | - | ||||||||||||
| 8 | */ | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | #include "internal/cryptlib_int.h" | - | ||||||||||||
| 11 | #include "internal/thread_once.h" | - | ||||||||||||
| 12 | - | |||||||||||||
| 13 | /* | - | ||||||||||||
| 14 | * Each structure type (sometimes called a class), that supports | - | ||||||||||||
| 15 | * exdata has a stack of callbacks for each instance. | - | ||||||||||||
| 16 | */ | - | ||||||||||||
| 17 | struct ex_callback_st { | - | ||||||||||||
| 18 | long argl; /* Arbitrary long */ | - | ||||||||||||
| 19 | void *argp; /* Arbitrary void * */ | - | ||||||||||||
| 20 | CRYPTO_EX_new *new_func; | - | ||||||||||||
| 21 | CRYPTO_EX_free *free_func; | - | ||||||||||||
| 22 | CRYPTO_EX_dup *dup_func; | - | ||||||||||||
| 23 | }; | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | /* | - | ||||||||||||
| 26 | * The state for each class. This could just be a typedef, but | - | ||||||||||||
| 27 | * a structure allows future changes. | - | ||||||||||||
| 28 | */ | - | ||||||||||||
| 29 | typedef struct ex_callbacks_st { | - | ||||||||||||
| 30 | STACK_OF(EX_CALLBACK) *meth; | - | ||||||||||||
| 31 | } EX_CALLBACKS; | - | ||||||||||||
| 32 | - | |||||||||||||
| 33 | static EX_CALLBACKS ex_data[CRYPTO_EX_INDEX__COUNT]; | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | static CRYPTO_RWLOCK *ex_data_lock = NULL; | - | ||||||||||||
| 36 | static CRYPTO_ONCE ex_data_init = CRYPTO_ONCE_STATIC_INIT; | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | DEFINE_RUN_ONCE_STATIC(do_ex_data_init) executed 2072 times by 12 tests: end of blockExecuted by:
| 2072 | ||||||||||||
| 39 | { | - | ||||||||||||
| 40 | if (!OPENSSL_init_crypto(0, NULL))
| 0-2072 | ||||||||||||
| 41 | return 0; never executed: return 0; | 0 | ||||||||||||
| 42 | ex_data_lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||
| 43 | return ex_data_lock != NULL; executed 2072 times by 12 tests: return ex_data_lock != ((void *)0) ;Executed by:
| 2072 | ||||||||||||
| 44 | } | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | /* | - | ||||||||||||
| 47 | * Return the EX_CALLBACKS from the |ex_data| array that corresponds to | - | ||||||||||||
| 48 | * a given class. On success, *holds the lock.* | - | ||||||||||||
| 49 | */ | - | ||||||||||||
| 50 | static EX_CALLBACKS *get_and_lock(int class_index) | - | ||||||||||||
| 51 | { | - | ||||||||||||
| 52 | EX_CALLBACKS *ip; | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | if (class_index < 0 || class_index >= CRYPTO_EX_INDEX__COUNT) {
| 0-771175 | ||||||||||||
| 55 | CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_PASSED_INVALID_ARGUMENT); | - | ||||||||||||
| 56 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 57 | } | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | if (!RUN_ONCE(&ex_data_init, do_ex_data_init)) {
| 0-771175 | ||||||||||||
| 60 | CRYPTOerr(CRYPTO_F_GET_AND_LOCK, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 61 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 62 | } | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | if (ex_data_lock == NULL) {
| 0-771175 | ||||||||||||
| 65 | /* | - | ||||||||||||
| 66 | * This can happen in normal operation when using CRYPTO_mem_leaks(). | - | ||||||||||||
| 67 | * The CRYPTO_mem_leaks() function calls OPENSSL_cleanup() which cleans | - | ||||||||||||
| 68 | * up the locks. Subsequently the BIO that CRYPTO_mem_leaks() uses gets | - | ||||||||||||
| 69 | * freed, which also attempts to free the ex_data. However | - | ||||||||||||
| 70 | * CRYPTO_mem_leaks() ensures that the ex_data is freed early (i.e. | - | ||||||||||||
| 71 | * before OPENSSL_cleanup() is called), so if we get here we can safely | - | ||||||||||||
| 72 | * ignore this operation. We just treat it as an error. | - | ||||||||||||
| 73 | */ | - | ||||||||||||
| 74 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 75 | } | - | ||||||||||||
| 76 | - | |||||||||||||
| 77 | ip = &ex_data[class_index]; | - | ||||||||||||
| 78 | CRYPTO_THREAD_write_lock(ex_data_lock); | - | ||||||||||||
| 79 | return ip; executed 771175 times by 12 tests: return ip;Executed by:
| 771175 | ||||||||||||
| 80 | } | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | static void cleanup_cb(EX_CALLBACK *funcs) | - | ||||||||||||
| 83 | { | - | ||||||||||||
| 84 | OPENSSL_free(funcs); | - | ||||||||||||
| 85 | } executed 2122 times by 1 test: end of blockExecuted by:
| 2122 | ||||||||||||
| 86 | - | |||||||||||||
| 87 | /* | - | ||||||||||||
| 88 | * Release all "ex_data" state to prevent memory leaks. This can't be made | - | ||||||||||||
| 89 | * thread-safe without overhauling a lot of stuff, and shouldn't really be | - | ||||||||||||
| 90 | * called under potential race-conditions anyway (it's for program shutdown | - | ||||||||||||
| 91 | * after all). | - | ||||||||||||
| 92 | */ | - | ||||||||||||
| 93 | void crypto_cleanup_all_ex_data_int(void) | - | ||||||||||||
| 94 | { | - | ||||||||||||
| 95 | int i; | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | for (i = 0; i < CRYPTO_EX_INDEX__COUNT; ++i) {
| 2076-33216 | ||||||||||||
| 98 | EX_CALLBACKS *ip = &ex_data[i]; | - | ||||||||||||
| 99 | - | |||||||||||||
| 100 | sk_EX_CALLBACK_pop_free(ip->meth, cleanup_cb); | - | ||||||||||||
| 101 | ip->meth = NULL; | - | ||||||||||||
| 102 | } executed 33216 times by 12 tests: end of blockExecuted by:
| 33216 | ||||||||||||
| 103 | - | |||||||||||||
| 104 | CRYPTO_THREAD_lock_free(ex_data_lock); | - | ||||||||||||
| 105 | ex_data_lock = NULL; | - | ||||||||||||
| 106 | } executed 2076 times by 12 tests: end of blockExecuted by:
| 2076 | ||||||||||||
| 107 | - | |||||||||||||
| 108 | - | |||||||||||||
| 109 | /* | - | ||||||||||||
| 110 | * Unregister a new index by replacing the callbacks with no-ops. | - | ||||||||||||
| 111 | * Any in-use instances are leaked. | - | ||||||||||||
| 112 | */ | - | ||||||||||||
| 113 | static void dummy_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, | - | ||||||||||||
| 114 | long argl, void *argp) | - | ||||||||||||
| 115 | { | - | ||||||||||||
| 116 | } | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | static void dummy_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, | - | ||||||||||||
| 119 | long argl, void *argp) | - | ||||||||||||
| 120 | { | - | ||||||||||||
| 121 | } | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | static int dummy_dup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, | - | ||||||||||||
| 124 | void *from_d, int idx, | - | ||||||||||||
| 125 | long argl, void *argp) | - | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | return 1; never executed: return 1; | 0 | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | int CRYPTO_free_ex_index(int class_index, int idx) | - | ||||||||||||
| 131 | { | - | ||||||||||||
| 132 | EX_CALLBACKS *ip = get_and_lock(class_index); | - | ||||||||||||
| 133 | EX_CALLBACK *a; | - | ||||||||||||
| 134 | int toret = 0; | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | if (ip == NULL)
| 0-8 | ||||||||||||
| 137 | return 0; never executed: return 0; | 0 | ||||||||||||
| 138 | if (idx < 0 || idx >= sk_EX_CALLBACK_num(ip->meth))
| 0-8 | ||||||||||||
| 139 | goto err; executed 8 times by 1 test: goto err;Executed by:
| 8 | ||||||||||||
| 140 | a = sk_EX_CALLBACK_value(ip->meth, idx); | - | ||||||||||||
| 141 | if (a == NULL)
| 0 | ||||||||||||
| 142 | goto err; never executed: goto err; | 0 | ||||||||||||
| 143 | a->new_func = dummy_new; | - | ||||||||||||
| 144 | a->dup_func = dummy_dup; | - | ||||||||||||
| 145 | a->free_func = dummy_free; | - | ||||||||||||
| 146 | toret = 1; | - | ||||||||||||
| 147 | err: code before this statement never executed: err: | 0 | ||||||||||||
| 148 | CRYPTO_THREAD_unlock(ex_data_lock); | - | ||||||||||||
| 149 | return toret; executed 8 times by 1 test: return toret;Executed by:
| 8 | ||||||||||||
| 150 | } | - | ||||||||||||
| 151 | - | |||||||||||||
| 152 | /* | - | ||||||||||||
| 153 | * Register a new index. | - | ||||||||||||
| 154 | */ | - | ||||||||||||
| 155 | int CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, | - | ||||||||||||
| 156 | CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, | - | ||||||||||||
| 157 | CRYPTO_EX_free *free_func) | - | ||||||||||||
| 158 | { | - | ||||||||||||
| 159 | int toret = -1; | - | ||||||||||||
| 160 | EX_CALLBACK *a; | - | ||||||||||||
| 161 | EX_CALLBACKS *ip = get_and_lock(class_index); | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | if (ip == NULL)
| 0-2122 | ||||||||||||
| 164 | return -1; never executed: return -1; | 0 | ||||||||||||
| 165 | - | |||||||||||||
| 166 | if (ip->meth == NULL) {
| 937-1185 | ||||||||||||
| 167 | ip->meth = sk_EX_CALLBACK_new_null(); | - | ||||||||||||
| 168 | /* We push an initial value on the stack because the SSL | - | ||||||||||||
| 169 | * "app_data" routines use ex_data index zero. See RT 3710. */ | - | ||||||||||||
| 170 | if (ip->meth == NULL
| 0-937 | ||||||||||||
| 171 | || !sk_EX_CALLBACK_push(ip->meth, NULL)) {
| 0-937 | ||||||||||||
| 172 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 173 | goto err; never executed: goto err; | 0 | ||||||||||||
| 174 | } | - | ||||||||||||
| 175 | } executed 937 times by 1 test: end of blockExecuted by:
| 937 | ||||||||||||
| 176 | - | |||||||||||||
| 177 | a = (EX_CALLBACK *)OPENSSL_malloc(sizeof(*a)); | - | ||||||||||||
| 178 | if (a == NULL) {
| 0-2122 | ||||||||||||
| 179 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 180 | goto err; never executed: goto err; | 0 | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | a->argl = argl; | - | ||||||||||||
| 183 | a->argp = argp; | - | ||||||||||||
| 184 | a->new_func = new_func; | - | ||||||||||||
| 185 | a->dup_func = dup_func; | - | ||||||||||||
| 186 | a->free_func = free_func; | - | ||||||||||||
| 187 | - | |||||||||||||
| 188 | if (!sk_EX_CALLBACK_push(ip->meth, NULL)) {
| 0-2122 | ||||||||||||
| 189 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_EX_NEW_INDEX, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 190 | OPENSSL_free(a); | - | ||||||||||||
| 191 | goto err; never executed: goto err; | 0 | ||||||||||||
| 192 | } | - | ||||||||||||
| 193 | toret = sk_EX_CALLBACK_num(ip->meth) - 1; | - | ||||||||||||
| 194 | (void)sk_EX_CALLBACK_set(ip->meth, toret, a); | - | ||||||||||||
| 195 | - | |||||||||||||
| 196 | err: code before this statement executed 2122 times by 1 test: err:Executed by:
| 2122 | ||||||||||||
| 197 | CRYPTO_THREAD_unlock(ex_data_lock); | - | ||||||||||||
| 198 | return toret; executed 2122 times by 1 test: return toret;Executed by:
| 2122 | ||||||||||||
| 199 | } | - | ||||||||||||
| 200 | - | |||||||||||||
| 201 | /* | - | ||||||||||||
| 202 | * Initialise a new CRYPTO_EX_DATA for use in a particular class - including | - | ||||||||||||
| 203 | * calling new() callbacks for each index in the class used by this variable | - | ||||||||||||
| 204 | * Thread-safe by copying a class's array of "EX_CALLBACK" entries | - | ||||||||||||
| 205 | * in the lock, then using them outside the lock. Note this only applies | - | ||||||||||||
| 206 | * to the global "ex_data" state (ie. class definitions), not 'ad' itself. | - | ||||||||||||
| 207 | */ | - | ||||||||||||
| 208 | int CRYPTO_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | int mx, i; | - | ||||||||||||
| 211 | void *ptr; | - | ||||||||||||
| 212 | EX_CALLBACK **storage = NULL; | - | ||||||||||||
| 213 | EX_CALLBACK *stack[10]; | - | ||||||||||||
| 214 | EX_CALLBACKS *ip = get_and_lock(class_index); | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | if (ip == NULL)
| 0-381421 | ||||||||||||
| 217 | return 0; never executed: return 0; | 0 | ||||||||||||
| 218 | - | |||||||||||||
| 219 | ad->sk = NULL; | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | mx = sk_EX_CALLBACK_num(ip->meth); | - | ||||||||||||
| 222 | if (mx > 0) {
| 7136-374285 | ||||||||||||
| 223 | if (mx < (int)OSSL_NELEM(stack))
| 2038-5098 | ||||||||||||
| 224 | storage = stack; executed 5098 times by 1 test: storage = stack;Executed by:
| 5098 | ||||||||||||
| 225 | else | - | ||||||||||||
| 226 | storage = OPENSSL_malloc(sizeof(*storage) * mx); executed 2038 times by 1 test: storage = CRYPTO_malloc(sizeof(*storage) * mx, __FILE__, 226);Executed by:
| 2038 | ||||||||||||
| 227 | if (storage != NULL)
| 0-7136 | ||||||||||||
| 228 | for (i = 0; i < mx; i++)
| 7136-499969 | ||||||||||||
| 229 | storage[i] = sk_EX_CALLBACK_value(ip->meth, i); executed 499969 times by 1 test: storage[i] = sk_EX_CALLBACK_value(ip->meth, i);Executed by:
| 499969 | ||||||||||||
| 230 | } executed 7136 times by 1 test: end of blockExecuted by:
| 7136 | ||||||||||||
| 231 | CRYPTO_THREAD_unlock(ex_data_lock); | - | ||||||||||||
| 232 | - | |||||||||||||
| 233 | if (mx > 0 && storage == NULL) {
| 0-374285 | ||||||||||||
| 234 | CRYPTOerr(CRYPTO_F_CRYPTO_NEW_EX_DATA, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 235 | return 0; never executed: return 0; | 0 | ||||||||||||
| 236 | } | - | ||||||||||||
| 237 | for (i = 0; i < mx; i++) {
| 381421-499969 | ||||||||||||
| 238 | if (storage[i] && storage[i]->new_func) {
| 7-492833 | ||||||||||||
| 239 | ptr = CRYPTO_get_ex_data(ad, i); | - | ||||||||||||
| 240 | storage[i]->new_func(obj, ptr, ad, i, | - | ||||||||||||
| 241 | storage[i]->argl, storage[i]->argp); | - | ||||||||||||
| 242 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 243 | } executed 499969 times by 1 test: end of blockExecuted by:
| 499969 | ||||||||||||
| 244 | if (storage != stack)
| 5098-376323 | ||||||||||||
| 245 | OPENSSL_free(storage); executed 376323 times by 12 tests: CRYPTO_free(storage, __FILE__, 245);Executed by:
| 376323 | ||||||||||||
| 246 | return 1; executed 381421 times by 12 tests: return 1;Executed by:
| 381421 | ||||||||||||
| 247 | } | - | ||||||||||||
| 248 | - | |||||||||||||
| 249 | /* | - | ||||||||||||
| 250 | * Duplicate a CRYPTO_EX_DATA variable - including calling dup() callbacks | - | ||||||||||||
| 251 | * for each index in the class used by this variable | - | ||||||||||||
| 252 | */ | - | ||||||||||||
| 253 | int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, | - | ||||||||||||
| 254 | const CRYPTO_EX_DATA *from) | - | ||||||||||||
| 255 | { | - | ||||||||||||
| 256 | int mx, j, i; | - | ||||||||||||
| 257 | void *ptr; | - | ||||||||||||
| 258 | EX_CALLBACK *stack[10]; | - | ||||||||||||
| 259 | EX_CALLBACK **storage = NULL; | - | ||||||||||||
| 260 | EX_CALLBACKS *ip; | - | ||||||||||||
| 261 | int toret = 0; | - | ||||||||||||
| 262 | - | |||||||||||||
| 263 | if (from->sk == NULL)
| 1-2890 | ||||||||||||
| 264 | /* Nothing to copy over */ | - | ||||||||||||
| 265 | return 1; executed 2890 times by 1 test: return 1;Executed by:
| 2890 | ||||||||||||
| 266 | if ((ip = get_and_lock(class_index)) == NULL)
| 0-1 | ||||||||||||
| 267 | return 0; never executed: return 0; | 0 | ||||||||||||
| 268 | - | |||||||||||||
| 269 | mx = sk_EX_CALLBACK_num(ip->meth); | - | ||||||||||||
| 270 | j = sk_void_num(from->sk); | - | ||||||||||||
| 271 | if (j < mx)
| 0-1 | ||||||||||||
| 272 | mx = j; never executed: mx = j; | 0 | ||||||||||||
| 273 | if (mx > 0) {
| 0-1 | ||||||||||||
| 274 | if (mx < (int)OSSL_NELEM(stack))
| 0-1 | ||||||||||||
| 275 | storage = stack; executed 1 time by 1 test: storage = stack;Executed by:
| 1 | ||||||||||||
| 276 | else | - | ||||||||||||
| 277 | storage = OPENSSL_malloc(sizeof(*storage) * mx); never executed: storage = CRYPTO_malloc(sizeof(*storage) * mx, __FILE__, 277); | 0 | ||||||||||||
| 278 | if (storage != NULL)
| 0-1 | ||||||||||||
| 279 | for (i = 0; i < mx; i++)
| 1-3 | ||||||||||||
| 280 | storage[i] = sk_EX_CALLBACK_value(ip->meth, i); executed 3 times by 1 test: storage[i] = sk_EX_CALLBACK_value(ip->meth, i);Executed by:
| 3 | ||||||||||||
| 281 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 282 | CRYPTO_THREAD_unlock(ex_data_lock); | - | ||||||||||||
| 283 | - | |||||||||||||
| 284 | if (mx == 0)
| 0-1 | ||||||||||||
| 285 | return 1; never executed: return 1; | 0 | ||||||||||||
| 286 | if (storage == NULL) {
| 0-1 | ||||||||||||
| 287 | CRYPTOerr(CRYPTO_F_CRYPTO_DUP_EX_DATA, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 288 | return 0; never executed: return 0; | 0 | ||||||||||||
| 289 | } | - | ||||||||||||
| 290 | /* | - | ||||||||||||
| 291 | * Make sure the ex_data stack is at least |mx| elements long to avoid | - | ||||||||||||
| 292 | * issues in the for loop that follows; so go get the |mx|'th element | - | ||||||||||||
| 293 | * (if it does not exist CRYPTO_get_ex_data() returns NULL), and assign | - | ||||||||||||
| 294 | * to itself. This is normally a no-op; but ensures the stack is the | - | ||||||||||||
| 295 | * proper size | - | ||||||||||||
| 296 | */ | - | ||||||||||||
| 297 | if (!CRYPTO_set_ex_data(to, mx - 1, CRYPTO_get_ex_data(to, mx - 1)))
| 0-1 | ||||||||||||
| 298 | goto err; never executed: goto err; | 0 | ||||||||||||
| 299 | - | |||||||||||||
| 300 | for (i = 0; i < mx; i++) {
| 1-3 | ||||||||||||
| 301 | ptr = CRYPTO_get_ex_data(from, i); | - | ||||||||||||
| 302 | if (storage[i] && storage[i]->dup_func)
| 0-2 | ||||||||||||
| 303 | if (!storage[i]->dup_func(to, from, &ptr, i,
| 0-2 | ||||||||||||
| 304 | storage[i]->argl, storage[i]->argp))
| 0-2 | ||||||||||||
| 305 | goto err; never executed: goto err; | 0 | ||||||||||||
| 306 | CRYPTO_set_ex_data(to, i, ptr); | - | ||||||||||||
| 307 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||
| 308 | toret = 1; | - | ||||||||||||
| 309 | err: code before this statement executed 1 time by 1 test: err:Executed by:
| 1 | ||||||||||||
| 310 | if (storage != stack)
| 0-1 | ||||||||||||
| 311 | OPENSSL_free(storage); never executed: CRYPTO_free(storage, __FILE__, 311); | 0 | ||||||||||||
| 312 | return toret; executed 1 time by 1 test: return toret;Executed by:
| 1 | ||||||||||||
| 313 | } | - | ||||||||||||
| 314 | - | |||||||||||||
| 315 | - | |||||||||||||
| 316 | /* | - | ||||||||||||
| 317 | * Cleanup a CRYPTO_EX_DATA variable - including calling free() callbacks for | - | ||||||||||||
| 318 | * each index in the class used by this variable | - | ||||||||||||
| 319 | */ | - | ||||||||||||
| 320 | void CRYPTO_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) | - | ||||||||||||
| 321 | { | - | ||||||||||||
| 322 | int mx, i; | - | ||||||||||||
| 323 | EX_CALLBACKS *ip; | - | ||||||||||||
| 324 | void *ptr; | - | ||||||||||||
| 325 | EX_CALLBACK *f; | - | ||||||||||||
| 326 | EX_CALLBACK *stack[10]; | - | ||||||||||||
| 327 | EX_CALLBACK **storage = NULL; | - | ||||||||||||
| 328 | - | |||||||||||||
| 329 | if ((ip = get_and_lock(class_index)) == NULL)
| 0-387623 | ||||||||||||
| 330 | goto err; never executed: goto err; | 0 | ||||||||||||
| 331 | - | |||||||||||||
| 332 | mx = sk_EX_CALLBACK_num(ip->meth); | - | ||||||||||||
| 333 | if (mx > 0) {
| 12318-375305 | ||||||||||||
| 334 | if (mx < (int)OSSL_NELEM(stack))
| 2072-10246 | ||||||||||||
| 335 | storage = stack; executed 10246 times by 1 test: storage = stack;Executed by:
| 10246 | ||||||||||||
| 336 | else | - | ||||||||||||
| 337 | storage = OPENSSL_malloc(sizeof(*storage) * mx); executed 2072 times by 1 test: storage = CRYPTO_malloc(sizeof(*storage) * mx, __FILE__, 337);Executed by:
| 2072 | ||||||||||||
| 338 | if (storage != NULL)
| 0-12318 | ||||||||||||
| 339 | for (i = 0; i < mx; i++)
| 12318-512701 | ||||||||||||
| 340 | storage[i] = sk_EX_CALLBACK_value(ip->meth, i); executed 512701 times by 1 test: storage[i] = sk_EX_CALLBACK_value(ip->meth, i);Executed by:
| 512701 | ||||||||||||
| 341 | } executed 12318 times by 1 test: end of blockExecuted by:
| 12318 | ||||||||||||
| 342 | CRYPTO_THREAD_unlock(ex_data_lock); | - | ||||||||||||
| 343 | - | |||||||||||||
| 344 | for (i = 0; i < mx; i++) {
| 387623-512701 | ||||||||||||
| 345 | if (storage != NULL)
| 0-512701 | ||||||||||||
| 346 | f = storage[i]; executed 512701 times by 1 test: f = storage[i];Executed by:
| 512701 | ||||||||||||
| 347 | else { | - | ||||||||||||
| 348 | CRYPTO_THREAD_write_lock(ex_data_lock); | - | ||||||||||||
| 349 | f = sk_EX_CALLBACK_value(ip->meth, i); | - | ||||||||||||
| 350 | CRYPTO_THREAD_unlock(ex_data_lock); | - | ||||||||||||
| 351 | } never executed: end of block | 0 | ||||||||||||
| 352 | if (f != NULL && f->free_func != NULL) {
| 744-500383 | ||||||||||||
| 353 | ptr = CRYPTO_get_ex_data(ad, i); | - | ||||||||||||
| 354 | f->free_func(obj, ptr, ad, i, f->argl, f->argp); | - | ||||||||||||
| 355 | } executed 744 times by 1 test: end of blockExecuted by:
| 744 | ||||||||||||
| 356 | } executed 512701 times by 1 test: end of blockExecuted by:
| 512701 | ||||||||||||
| 357 | - | |||||||||||||
| 358 | if (storage != stack)
| 10246-377377 | ||||||||||||
| 359 | OPENSSL_free(storage); executed 377377 times by 12 tests: CRYPTO_free(storage, __FILE__, 359);Executed by:
| 377377 | ||||||||||||
| 360 | err: code before this statement executed 387623 times by 12 tests: err:Executed by:
| 387623 | ||||||||||||
| 361 | sk_void_free(ad->sk); | - | ||||||||||||
| 362 | ad->sk = NULL; | - | ||||||||||||
| 363 | } executed 387623 times by 12 tests: end of blockExecuted by:
| 387623 | ||||||||||||
| 364 | - | |||||||||||||
| 365 | /* | - | ||||||||||||
| 366 | * For a given CRYPTO_EX_DATA variable, set the value corresponding to a | - | ||||||||||||
| 367 | * particular index in the class used by this variable | - | ||||||||||||
| 368 | */ | - | ||||||||||||
| 369 | int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val) | - | ||||||||||||
| 370 | { | - | ||||||||||||
| 371 | int i; | - | ||||||||||||
| 372 | - | |||||||||||||
| 373 | if (ad->sk == NULL) {
| 14-9787 | ||||||||||||
| 374 | if ((ad->sk = sk_void_new_null()) == NULL) {
| 0-9787 | ||||||||||||
| 375 | CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 376 | return 0; never executed: return 0; | 0 | ||||||||||||
| 377 | } | - | ||||||||||||
| 378 | } executed 9787 times by 1 test: end of blockExecuted by:
| 9787 | ||||||||||||
| 379 | - | |||||||||||||
| 380 | for (i = sk_void_num(ad->sk); i <= idx; ++i) {
| 9801-507639 | ||||||||||||
| 381 | if (!sk_void_push(ad->sk, NULL)) {
| 0-507639 | ||||||||||||
| 382 | CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 383 | return 0; never executed: return 0; | 0 | ||||||||||||
| 384 | } | - | ||||||||||||
| 385 | } executed 507639 times by 1 test: end of blockExecuted by:
| 507639 | ||||||||||||
| 386 | sk_void_set(ad->sk, idx, val); | - | ||||||||||||
| 387 | return 1; executed 9801 times by 1 test: return 1;Executed by:
| 9801 | ||||||||||||
| 388 | } | - | ||||||||||||
| 389 | - | |||||||||||||
| 390 | /* | - | ||||||||||||
| 391 | * For a given CRYPTO_EX_DATA_ variable, get the value corresponding to a | - | ||||||||||||
| 392 | * particular index in the class used by this variable | - | ||||||||||||
| 393 | */ | - | ||||||||||||
| 394 | void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx) | - | ||||||||||||
| 395 | { | - | ||||||||||||
| 396 | if (ad->sk == NULL || idx >= sk_void_num(ad->sk))
| 0-16985 | ||||||||||||
| 397 | return NULL; executed 1112 times by 1 test: return ((void *)0) ;Executed by:
| 1112 | ||||||||||||
| 398 | return sk_void_value(ad->sk, idx); executed 16985 times by 1 test: return sk_void_value(ad->sk, idx);Executed by:
| 16985 | ||||||||||||
| 399 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |