diff options
| author | djm <> | 2008-09-06 12:17:54 +0000 |
|---|---|---|
| committer | djm <> | 2008-09-06 12:17:54 +0000 |
| commit | 6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda (patch) | |
| tree | 7ccc28afe1789ea3dbedf72365f955d5b8e105b5 /src/lib/libcrypto/err/err.c | |
| parent | 89181603212b41e95cde36b1be5a146ce8fb2935 (diff) | |
| download | openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.tar.gz openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.tar.bz2 openbsd-6b62d1fdd8a4fd35acfcc0c4bb1bf8b757fa8cda.zip | |
resolve conflicts
Diffstat (limited to 'src/lib/libcrypto/err/err.c')
| -rw-r--r-- | src/lib/libcrypto/err/err.c | 86 |
1 files changed, 68 insertions, 18 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index 53687d79ab..b6ff070e8f 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c | |||
| @@ -112,9 +112,9 @@ | |||
| 112 | #include <stdio.h> | 112 | #include <stdio.h> |
| 113 | #include <stdarg.h> | 113 | #include <stdarg.h> |
| 114 | #include <string.h> | 114 | #include <string.h> |
| 115 | #include "cryptlib.h" | ||
| 115 | #include <openssl/lhash.h> | 116 | #include <openssl/lhash.h> |
| 116 | #include <openssl/crypto.h> | 117 | #include <openssl/crypto.h> |
| 117 | #include "cryptlib.h" | ||
| 118 | #include <openssl/buffer.h> | 118 | #include <openssl/buffer.h> |
| 119 | #include <openssl/bio.h> | 119 | #include <openssl/bio.h> |
| 120 | #include <openssl/err.h> | 120 | #include <openssl/err.h> |
| @@ -149,7 +149,7 @@ static ERR_STRING_DATA ERR_str_libraries[]= | |||
| 149 | {ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"}, | 149 | {ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"}, |
| 150 | {ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"}, | 150 | {ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"}, |
| 151 | {ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"}, | 151 | {ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"}, |
| 152 | {ERR_PACK(ERR_LIB_FIPS,0,0) ,"FIPS routines"}, | 152 | {ERR_PACK(ERR_LIB_CMS,0,0) ,"CMS routines"}, |
| 153 | {0,NULL}, | 153 | {0,NULL}, |
| 154 | }; | 154 | }; |
| 155 | 155 | ||
| @@ -168,7 +168,6 @@ static ERR_STRING_DATA ERR_str_functs[]= | |||
| 168 | #endif | 168 | #endif |
| 169 | {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"}, | 169 | {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"}, |
| 170 | {ERR_PACK(0,SYS_F_FREAD,0), "fread"}, | 170 | {ERR_PACK(0,SYS_F_FREAD,0), "fread"}, |
| 171 | {ERR_PACK(0,SYS_F_GETADDRINFO,0), "getaddrinfo"}, | ||
| 172 | {0,NULL}, | 171 | {0,NULL}, |
| 173 | }; | 172 | }; |
| 174 | 173 | ||
| @@ -210,6 +209,7 @@ static ERR_STRING_DATA ERR_str_reasons[]= | |||
| 210 | {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"}, | 209 | {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"}, |
| 211 | {ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"}, | 210 | {ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"}, |
| 212 | {ERR_R_INTERNAL_ERROR ,"internal error"}, | 211 | {ERR_R_INTERNAL_ERROR ,"internal error"}, |
| 212 | {ERR_R_DISABLED ,"called a function that was disabled at compile-time"}, | ||
| 213 | 213 | ||
| 214 | {0,NULL}, | 214 | {0,NULL}, |
| 215 | }; | 215 | }; |
| @@ -542,16 +542,27 @@ static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1]; | |||
| 542 | * will be returned for SYSerr(), which always gets an errno | 542 | * will be returned for SYSerr(), which always gets an errno |
| 543 | * value and never one of those 'standard' reason codes. */ | 543 | * value and never one of those 'standard' reason codes. */ |
| 544 | 544 | ||
| 545 | static void build_SYS_str_reasons() | 545 | static void build_SYS_str_reasons(void) |
| 546 | { | 546 | { |
| 547 | /* OPENSSL_malloc cannot be used here, use static storage instead */ | 547 | /* OPENSSL_malloc cannot be used here, use static storage instead */ |
| 548 | static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; | 548 | static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; |
| 549 | int i; | 549 | int i; |
| 550 | static int init = 1; | 550 | static int init = 1; |
| 551 | 551 | ||
| 552 | if (!init) return; | 552 | CRYPTO_r_lock(CRYPTO_LOCK_ERR); |
| 553 | 553 | if (!init) | |
| 554 | { | ||
| 555 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | ||
| 556 | return; | ||
| 557 | } | ||
| 558 | |||
| 559 | CRYPTO_r_unlock(CRYPTO_LOCK_ERR); | ||
| 554 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); | 560 | CRYPTO_w_lock(CRYPTO_LOCK_ERR); |
| 561 | if (!init) | ||
| 562 | { | ||
| 563 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | ||
| 564 | return; | ||
| 565 | } | ||
| 555 | 566 | ||
| 556 | for (i = 1; i <= NUM_SYS_STR_REASONS; i++) | 567 | for (i = 1; i <= NUM_SYS_STR_REASONS; i++) |
| 557 | { | 568 | { |
| @@ -583,13 +594,24 @@ static void build_SYS_str_reasons() | |||
| 583 | #endif | 594 | #endif |
| 584 | 595 | ||
| 585 | #define err_clear_data(p,i) \ | 596 | #define err_clear_data(p,i) \ |
| 597 | do { \ | ||
| 586 | if (((p)->err_data[i] != NULL) && \ | 598 | if (((p)->err_data[i] != NULL) && \ |
| 587 | (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ | 599 | (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ |
| 588 | { \ | 600 | { \ |
| 589 | OPENSSL_free((p)->err_data[i]); \ | 601 | OPENSSL_free((p)->err_data[i]); \ |
| 590 | (p)->err_data[i]=NULL; \ | 602 | (p)->err_data[i]=NULL; \ |
| 591 | } \ | 603 | } \ |
| 592 | (p)->err_data_flags[i]=0; | 604 | (p)->err_data_flags[i]=0; \ |
| 605 | } while(0) | ||
| 606 | |||
| 607 | #define err_clear(p,i) \ | ||
| 608 | do { \ | ||
| 609 | (p)->err_flags[i]=0; \ | ||
| 610 | (p)->err_buffer[i]=0; \ | ||
| 611 | err_clear_data(p,i); \ | ||
| 612 | (p)->err_file[i]=NULL; \ | ||
| 613 | (p)->err_line[i]= -1; \ | ||
| 614 | } while(0) | ||
| 593 | 615 | ||
| 594 | static void ERR_STATE_free(ERR_STATE *s) | 616 | static void ERR_STATE_free(ERR_STATE *s) |
| 595 | { | 617 | { |
| @@ -682,6 +704,7 @@ void ERR_put_error(int lib, int func, int reason, const char *file, | |||
| 682 | es->top=(es->top+1)%ERR_NUM_ERRORS; | 704 | es->top=(es->top+1)%ERR_NUM_ERRORS; |
| 683 | if (es->top == es->bottom) | 705 | if (es->top == es->bottom) |
| 684 | es->bottom=(es->bottom+1)%ERR_NUM_ERRORS; | 706 | es->bottom=(es->bottom+1)%ERR_NUM_ERRORS; |
| 707 | es->err_flags[es->top]=0; | ||
| 685 | es->err_buffer[es->top]=ERR_PACK(lib,func,reason); | 708 | es->err_buffer[es->top]=ERR_PACK(lib,func,reason); |
| 686 | es->err_file[es->top]=file; | 709 | es->err_file[es->top]=file; |
| 687 | es->err_line[es->top]=line; | 710 | es->err_line[es->top]=line; |
| @@ -697,10 +720,7 @@ void ERR_clear_error(void) | |||
| 697 | 720 | ||
| 698 | for (i=0; i<ERR_NUM_ERRORS; i++) | 721 | for (i=0; i<ERR_NUM_ERRORS; i++) |
| 699 | { | 722 | { |
| 700 | es->err_buffer[i]=0; | 723 | err_clear(es,i); |
| 701 | err_clear_data(es,i); | ||
| 702 | es->err_file[i]=NULL; | ||
| 703 | es->err_line[i]= -1; | ||
| 704 | } | 724 | } |
| 705 | es->top=es->bottom=0; | 725 | es->top=es->bottom=0; |
| 706 | } | 726 | } |
| @@ -937,7 +957,7 @@ static unsigned long err_hash(const void *a_void) | |||
| 937 | { | 957 | { |
| 938 | unsigned long ret,l; | 958 | unsigned long ret,l; |
| 939 | 959 | ||
| 940 | l=((ERR_STRING_DATA *)a_void)->error; | 960 | l=((const ERR_STRING_DATA *)a_void)->error; |
| 941 | ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); | 961 | ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); |
| 942 | return(ret^ret%19*13); | 962 | return(ret^ret%19*13); |
| 943 | } | 963 | } |
| @@ -945,21 +965,21 @@ static unsigned long err_hash(const void *a_void) | |||
| 945 | /* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */ | 965 | /* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */ |
| 946 | static int err_cmp(const void *a_void, const void *b_void) | 966 | static int err_cmp(const void *a_void, const void *b_void) |
| 947 | { | 967 | { |
| 948 | return((int)(((ERR_STRING_DATA *)a_void)->error - | 968 | return((int)(((const ERR_STRING_DATA *)a_void)->error - |
| 949 | ((ERR_STRING_DATA *)b_void)->error)); | 969 | ((const ERR_STRING_DATA *)b_void)->error)); |
| 950 | } | 970 | } |
| 951 | 971 | ||
| 952 | /* static unsigned long pid_hash(ERR_STATE *a) */ | 972 | /* static unsigned long pid_hash(ERR_STATE *a) */ |
| 953 | static unsigned long pid_hash(const void *a_void) | 973 | static unsigned long pid_hash(const void *a_void) |
| 954 | { | 974 | { |
| 955 | return(((ERR_STATE *)a_void)->pid*13); | 975 | return(((const ERR_STATE *)a_void)->pid*13); |
| 956 | } | 976 | } |
| 957 | 977 | ||
| 958 | /* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */ | 978 | /* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */ |
| 959 | static int pid_cmp(const void *a_void, const void *b_void) | 979 | static int pid_cmp(const void *a_void, const void *b_void) |
| 960 | { | 980 | { |
| 961 | return((int)((long)((ERR_STATE *)a_void)->pid - | 981 | return((int)((long)((const ERR_STATE *)a_void)->pid - |
| 962 | (long)((ERR_STATE *)b_void)->pid)); | 982 | (long)((const ERR_STATE *)b_void)->pid)); |
| 963 | } | 983 | } |
| 964 | 984 | ||
| 965 | void ERR_remove_state(unsigned long pid) | 985 | void ERR_remove_state(unsigned long pid) |
| @@ -1069,7 +1089,7 @@ void ERR_add_error_data(int num, ...) | |||
| 1069 | else | 1089 | else |
| 1070 | str=p; | 1090 | str=p; |
| 1071 | } | 1091 | } |
| 1072 | BUF_strlcat(str,a,s+1); | 1092 | BUF_strlcat(str,a,(size_t)s+1); |
| 1073 | } | 1093 | } |
| 1074 | } | 1094 | } |
| 1075 | ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); | 1095 | ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); |
| @@ -1077,3 +1097,33 @@ void ERR_add_error_data(int num, ...) | |||
| 1077 | err: | 1097 | err: |
| 1078 | va_end(args); | 1098 | va_end(args); |
| 1079 | } | 1099 | } |
| 1100 | |||
| 1101 | int ERR_set_mark(void) | ||
| 1102 | { | ||
| 1103 | ERR_STATE *es; | ||
| 1104 | |||
| 1105 | es=ERR_get_state(); | ||
| 1106 | |||
| 1107 | if (es->bottom == es->top) return 0; | ||
| 1108 | es->err_flags[es->top]|=ERR_FLAG_MARK; | ||
| 1109 | return 1; | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | int ERR_pop_to_mark(void) | ||
| 1113 | { | ||
| 1114 | ERR_STATE *es; | ||
| 1115 | |||
| 1116 | es=ERR_get_state(); | ||
| 1117 | |||
| 1118 | while(es->bottom != es->top | ||
| 1119 | && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) | ||
| 1120 | { | ||
| 1121 | err_clear(es,es->top); | ||
| 1122 | es->top-=1; | ||
| 1123 | if (es->top == -1) es->top=ERR_NUM_ERRORS-1; | ||
| 1124 | } | ||
| 1125 | |||
| 1126 | if (es->bottom == es->top) return 0; | ||
| 1127 | es->err_flags[es->top]&=~ERR_FLAG_MARK; | ||
| 1128 | return 1; | ||
| 1129 | } | ||
