diff options
Diffstat (limited to 'src/lib/libcrypto/ex_data.c')
| -rw-r--r-- | src/lib/libcrypto/ex_data.c | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c index 0b27d57b45..77a91c4b04 100644 --- a/src/lib/libcrypto/ex_data.c +++ b/src/lib/libcrypto/ex_data.c | |||
| @@ -34,21 +34,21 @@ | |||
| 34 | * This package is an SSL implementation written | 34 | * This package is an SSL implementation written |
| 35 | * by Eric Young (eay@cryptsoft.com). | 35 | * by Eric Young (eay@cryptsoft.com). |
| 36 | * The implementation was written so as to conform with Netscapes SSL. | 36 | * The implementation was written so as to conform with Netscapes SSL. |
| 37 | * | 37 | * |
| 38 | * This library is free for commercial and non-commercial use as long as | 38 | * This library is free for commercial and non-commercial use as long as |
| 39 | * the following conditions are aheared to. The following conditions | 39 | * the following conditions are aheared to. The following conditions |
| 40 | * apply to all code found in this distribution, be it the RC4, RSA, | 40 | * apply to all code found in this distribution, be it the RC4, RSA, |
| 41 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 41 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
| 42 | * included with this distribution is covered by the same copyright terms | 42 | * included with this distribution is covered by the same copyright terms |
| 43 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 43 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
| 44 | * | 44 | * |
| 45 | * Copyright remains Eric Young's, and as such any Copyright notices in | 45 | * Copyright remains Eric Young's, and as such any Copyright notices in |
| 46 | * the code are not to be removed. | 46 | * the code are not to be removed. |
| 47 | * If this package is used in a product, Eric Young should be given attribution | 47 | * If this package is used in a product, Eric Young should be given attribution |
| 48 | * as the author of the parts of the library used. | 48 | * as the author of the parts of the library used. |
| 49 | * This can be in the form of a textual message at program startup or | 49 | * This can be in the form of a textual message at program startup or |
| 50 | * in documentation (online or textual) provided with the package. | 50 | * in documentation (online or textual) provided with the package. |
| 51 | * | 51 | * |
| 52 | * Redistribution and use in source and binary forms, with or without | 52 | * Redistribution and use in source and binary forms, with or without |
| 53 | * modification, are permitted provided that the following conditions | 53 | * modification, are permitted provided that the following conditions |
| 54 | * are met: | 54 | * are met: |
| @@ -63,10 +63,10 @@ | |||
| 63 | * Eric Young (eay@cryptsoft.com)" | 63 | * Eric Young (eay@cryptsoft.com)" |
| 64 | * The word 'cryptographic' can be left out if the rouines from the library | 64 | * The word 'cryptographic' can be left out if the rouines from the library |
| 65 | * being used are not cryptographic related :-). | 65 | * being used are not cryptographic related :-). |
| 66 | * 4. If you include any Windows specific code (or a derivative thereof) from | 66 | * 4. If you include any Windows specific code (or a derivative thereof) from |
| 67 | * the apps directory (application code) you must include an acknowledgement: | 67 | * the apps directory (application code) you must include an acknowledgement: |
| 68 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 68 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
| 69 | * | 69 | * |
| 70 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 70 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
| 71 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 71 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 72 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 72 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| @@ -78,7 +78,7 @@ | |||
| 78 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 78 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 79 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 79 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 80 | * SUCH DAMAGE. | 80 | * SUCH DAMAGE. |
| 81 | * | 81 | * |
| 82 | * The licence and distribution terms for any publically available version or | 82 | * The licence and distribution terms for any publically available version or |
| 83 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 83 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
| 84 | * copied and put under another distribution licence | 84 | * copied and put under another distribution licence |
| @@ -92,7 +92,7 @@ | |||
| 92 | * are met: | 92 | * are met: |
| 93 | * | 93 | * |
| 94 | * 1. Redistributions of source code must retain the above copyright | 94 | * 1. Redistributions of source code must retain the above copyright |
| 95 | * notice, this list of conditions and the following disclaimer. | 95 | * notice, this list of conditions and the following disclaimer. |
| 96 | * | 96 | * |
| 97 | * 2. Redistributions in binary form must reproduce the above copyright | 97 | * 2. Redistributions in binary form must reproduce the above copyright |
| 98 | * notice, this list of conditions and the following disclaimer in | 98 | * notice, this list of conditions and the following disclaimer in |
| @@ -276,9 +276,9 @@ ex_data_check(void) | |||
| 276 | { | 276 | { |
| 277 | int toret = 1; | 277 | int toret = 1; |
| 278 | CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); | 278 | CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); |
| 279 | if (!ex_data | 279 | if (!ex_data && |
| 280 | && (ex_data = lh_EX_CLASS_ITEM_new()) == NULL) | 280 | (ex_data = lh_EX_CLASS_ITEM_new()) == NULL) |
| 281 | toret = 0; | 281 | toret = 0; |
| 282 | CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); | 282 | CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); |
| 283 | return toret; | 283 | return toret; |
| 284 | } | 284 | } |
| @@ -344,7 +344,7 @@ def_add_index(EX_CLASS_ITEM *item, long argl, void *argp, | |||
| 344 | { | 344 | { |
| 345 | int toret = -1; | 345 | int toret = -1; |
| 346 | CRYPTO_EX_DATA_FUNCS *a = (CRYPTO_EX_DATA_FUNCS *)malloc( | 346 | CRYPTO_EX_DATA_FUNCS *a = (CRYPTO_EX_DATA_FUNCS *)malloc( |
| 347 | sizeof(CRYPTO_EX_DATA_FUNCS)); | 347 | sizeof(CRYPTO_EX_DATA_FUNCS)); |
| 348 | if (!a) { | 348 | if (!a) { |
| 349 | CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX, ERR_R_MALLOC_FAILURE); | 349 | CRYPTOerr(CRYPTO_F_DEF_ADD_INDEX, ERR_R_MALLOC_FAILURE); |
| 350 | return -1; | 350 | return -1; |
| @@ -376,6 +376,7 @@ static int | |||
| 376 | int_new_class(void) | 376 | int_new_class(void) |
| 377 | { | 377 | { |
| 378 | int toret; | 378 | int toret; |
| 379 | |||
| 379 | CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); | 380 | CRYPTO_w_lock(CRYPTO_LOCK_EX_DATA); |
| 380 | toret = ex_class++; | 381 | toret = ex_class++; |
| 381 | CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); | 382 | CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); |
| @@ -395,9 +396,10 @@ int_cleanup(void) | |||
| 395 | static int | 396 | static int |
| 396 | int_get_new_index(int class_index, long argl, void *argp, | 397 | int_get_new_index(int class_index, long argl, void *argp, |
| 397 | CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, | 398 | CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func, |
| 398 | CRYPTO_EX_free *free_func) | 399 | CRYPTO_EX_free *free_func) |
| 399 | { | 400 | { |
| 400 | EX_CLASS_ITEM *item = def_get_class(class_index); | 401 | EX_CLASS_ITEM *item = def_get_class(class_index); |
| 402 | |||
| 401 | if (!item) | 403 | if (!item) |
| 402 | return -1; | 404 | return -1; |
| 403 | return def_add_index(item, argl, argp, new_func, dup_func, free_func); | 405 | return def_add_index(item, argl, argp, new_func, dup_func, free_func); |
| @@ -408,13 +410,13 @@ CRYPTO_EX_free *free_func) | |||
| 408 | * the global "ex_data" state (ie. class definitions), not thread-safe on 'ad' | 410 | * the global "ex_data" state (ie. class definitions), not thread-safe on 'ad' |
| 409 | * itself. */ | 411 | * itself. */ |
| 410 | static int | 412 | static int |
| 411 | int_new_ex_data(int class_index, void *obj, | 413 | int_new_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) |
| 412 | CRYPTO_EX_DATA *ad) | ||
| 413 | { | 414 | { |
| 414 | int mx, i; | 415 | int mx, i; |
| 415 | void *ptr; | 416 | void *ptr; |
| 416 | CRYPTO_EX_DATA_FUNCS **storage = NULL; | 417 | CRYPTO_EX_DATA_FUNCS **storage = NULL; |
| 417 | EX_CLASS_ITEM *item = def_get_class(class_index); | 418 | EX_CLASS_ITEM *item = def_get_class(class_index); |
| 419 | |||
| 418 | if (!item) | 420 | if (!item) |
| 419 | /* error is already set */ | 421 | /* error is already set */ |
| 420 | return 0; | 422 | return 0; |
| @@ -426,7 +428,8 @@ int_new_ex_data(int class_index, void *obj, | |||
| 426 | if (!storage) | 428 | if (!storage) |
| 427 | goto skip; | 429 | goto skip; |
| 428 | for (i = 0; i < mx; i++) | 430 | for (i = 0; i < mx; i++) |
| 429 | storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth, i); | 431 | storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value( |
| 432 | item->meth, i); | ||
| 430 | } | 433 | } |
| 431 | skip: | 434 | skip: |
| 432 | CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); | 435 | CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); |
| @@ -438,7 +441,7 @@ skip: | |||
| 438 | if (storage[i] && storage[i]->new_func) { | 441 | if (storage[i] && storage[i]->new_func) { |
| 439 | ptr = CRYPTO_get_ex_data(ad, i); | 442 | ptr = CRYPTO_get_ex_data(ad, i); |
| 440 | storage[i]->new_func(obj, ptr, ad, i, | 443 | storage[i]->new_func(obj, ptr, ad, i, |
| 441 | storage[i]->argl, storage[i]->argp); | 444 | storage[i]->argl, storage[i]->argp); |
| 442 | } | 445 | } |
| 443 | } | 446 | } |
| 444 | if (storage) | 447 | if (storage) |
| @@ -448,13 +451,13 @@ skip: | |||
| 448 | 451 | ||
| 449 | /* Same thread-safety notes as for "int_new_ex_data" */ | 452 | /* Same thread-safety notes as for "int_new_ex_data" */ |
| 450 | static int | 453 | static int |
| 451 | int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, | 454 | int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from) |
| 452 | CRYPTO_EX_DATA *from) | ||
| 453 | { | 455 | { |
| 454 | int mx, j, i; | 456 | int mx, j, i; |
| 455 | char *ptr; | 457 | char *ptr; |
| 456 | CRYPTO_EX_DATA_FUNCS **storage = NULL; | 458 | CRYPTO_EX_DATA_FUNCS **storage = NULL; |
| 457 | EX_CLASS_ITEM *item; | 459 | EX_CLASS_ITEM *item; |
| 460 | |||
| 458 | if (!from->sk) | 461 | if (!from->sk) |
| 459 | /* 'to' should be "blank" which *is* just like 'from' */ | 462 | /* 'to' should be "blank" which *is* just like 'from' */ |
| 460 | return 1; | 463 | return 1; |
| @@ -470,7 +473,8 @@ int_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, | |||
| 470 | if (!storage) | 473 | if (!storage) |
| 471 | goto skip; | 474 | goto skip; |
| 472 | for (i = 0; i < mx; i++) | 475 | for (i = 0; i < mx; i++) |
| 473 | storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth, i); | 476 | storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value( |
| 477 | item->meth, i); | ||
| 474 | } | 478 | } |
| 475 | skip: | 479 | skip: |
| 476 | CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); | 480 | CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); |
| @@ -507,7 +511,8 @@ int_free_ex_data(int class_index, void *obj, CRYPTO_EX_DATA *ad) | |||
| 507 | if (!storage) | 511 | if (!storage) |
| 508 | goto skip; | 512 | goto skip; |
| 509 | for (i = 0; i < mx; i++) | 513 | for (i = 0; i < mx; i++) |
| 510 | storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value(item->meth, i); | 514 | storage[i] = sk_CRYPTO_EX_DATA_FUNCS_value( |
| 515 | item->meth, i); | ||
| 511 | } | 516 | } |
| 512 | skip: | 517 | skip: |
| 513 | CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); | 518 | CRYPTO_r_unlock(CRYPTO_LOCK_EX_DATA); |
| @@ -519,7 +524,7 @@ skip: | |||
| 519 | if (storage[i] && storage[i]->free_func) { | 524 | if (storage[i] && storage[i]->free_func) { |
| 520 | ptr = CRYPTO_get_ex_data(ad, i); | 525 | ptr = CRYPTO_get_ex_data(ad, i); |
| 521 | storage[i]->free_func(obj, ptr, ad, i, | 526 | storage[i]->free_func(obj, ptr, ad, i, |
| 522 | storage[i]->argl, storage[i]->argp); | 527 | storage[i]->argl, storage[i]->argp); |
| 523 | } | 528 | } |
| 524 | } | 529 | } |
| 525 | if (storage) | 530 | if (storage) |
| @@ -563,7 +568,7 @@ CRYPTO_get_ex_new_index(int class_index, long argl, void *argp, | |||
| 563 | 568 | ||
| 564 | IMPL_CHECK | 569 | IMPL_CHECK |
| 565 | ret = EX_IMPL(get_new_index)(class_index, | 570 | ret = EX_IMPL(get_new_index)(class_index, |
| 566 | argl, argp, new_func, dup_func, free_func); | 571 | argl, argp, new_func, dup_func, free_func); |
| 567 | return ret; | 572 | return ret; |
| 568 | } | 573 | } |
| 569 | 574 | ||
| @@ -603,7 +608,8 @@ CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val) | |||
| 603 | 608 | ||
| 604 | if (ad->sk == NULL) { | 609 | if (ad->sk == NULL) { |
| 605 | if ((ad->sk = sk_void_new_null()) == NULL) { | 610 | if ((ad->sk = sk_void_new_null()) == NULL) { |
| 606 | CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, ERR_R_MALLOC_FAILURE); | 611 | CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, |
| 612 | ERR_R_MALLOC_FAILURE); | ||
| 607 | return (0); | 613 | return (0); |
| 608 | } | 614 | } |
| 609 | } | 615 | } |
| @@ -611,7 +617,8 @@ CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int idx, void *val) | |||
| 611 | 617 | ||
| 612 | while (i <= idx) { | 618 | while (i <= idx) { |
| 613 | if (!sk_void_push(ad->sk, NULL)) { | 619 | if (!sk_void_push(ad->sk, NULL)) { |
| 614 | CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, ERR_R_MALLOC_FAILURE); | 620 | CRYPTOerr(CRYPTO_F_CRYPTO_SET_EX_DATA, |
| 621 | ERR_R_MALLOC_FAILURE); | ||
| 615 | return (0); | 622 | return (0); |
| 616 | } | 623 | } |
| 617 | i++; | 624 | i++; |
