summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/err/err.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/err/err.c')
-rw-r--r--src/lib/libcrypto/err/err.c86
1 files changed, 18 insertions, 68 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index b6ff070e8f..53687d79ab 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"
116#include <openssl/lhash.h> 115#include <openssl/lhash.h>
117#include <openssl/crypto.h> 116#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_CMS,0,0) ,"CMS routines"}, 152{ERR_PACK(ERR_LIB_FIPS,0,0) ,"FIPS routines"},
153{0,NULL}, 153{0,NULL},
154 }; 154 };
155 155
@@ -168,6 +168,7 @@ 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"},
171 {0,NULL}, 172 {0,NULL},
172 }; 173 };
173 174
@@ -209,7 +210,6 @@ static ERR_STRING_DATA ERR_str_reasons[]=
209{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"}, 210{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
210{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"}, 211{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
211{ERR_R_INTERNAL_ERROR ,"internal error"}, 212{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,27 +542,16 @@ 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
545static void build_SYS_str_reasons(void) 545static void build_SYS_str_reasons()
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 CRYPTO_r_lock(CRYPTO_LOCK_ERR); 552 if (!init) return;
553 if (!init) 553
554 {
555 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
556 return;
557 }
558
559 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
560 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 554 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
561 if (!init)
562 {
563 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
564 return;
565 }
566 555
567 for (i = 1; i <= NUM_SYS_STR_REASONS; i++) 556 for (i = 1; i <= NUM_SYS_STR_REASONS; i++)
568 { 557 {
@@ -594,24 +583,13 @@ static void build_SYS_str_reasons(void)
594#endif 583#endif
595 584
596#define err_clear_data(p,i) \ 585#define err_clear_data(p,i) \
597 do { \
598 if (((p)->err_data[i] != NULL) && \ 586 if (((p)->err_data[i] != NULL) && \
599 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ 587 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
600 { \ 588 { \
601 OPENSSL_free((p)->err_data[i]); \ 589 OPENSSL_free((p)->err_data[i]); \
602 (p)->err_data[i]=NULL; \ 590 (p)->err_data[i]=NULL; \
603 } \ 591 } \
604 (p)->err_data_flags[i]=0; \ 592 (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)
615 593
616static void ERR_STATE_free(ERR_STATE *s) 594static void ERR_STATE_free(ERR_STATE *s)
617 { 595 {
@@ -704,7 +682,6 @@ void ERR_put_error(int lib, int func, int reason, const char *file,
704 es->top=(es->top+1)%ERR_NUM_ERRORS; 682 es->top=(es->top+1)%ERR_NUM_ERRORS;
705 if (es->top == es->bottom) 683 if (es->top == es->bottom)
706 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS; 684 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
707 es->err_flags[es->top]=0;
708 es->err_buffer[es->top]=ERR_PACK(lib,func,reason); 685 es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
709 es->err_file[es->top]=file; 686 es->err_file[es->top]=file;
710 es->err_line[es->top]=line; 687 es->err_line[es->top]=line;
@@ -720,7 +697,10 @@ void ERR_clear_error(void)
720 697
721 for (i=0; i<ERR_NUM_ERRORS; i++) 698 for (i=0; i<ERR_NUM_ERRORS; i++)
722 { 699 {
723 err_clear(es,i); 700 es->err_buffer[i]=0;
701 err_clear_data(es,i);
702 es->err_file[i]=NULL;
703 es->err_line[i]= -1;
724 } 704 }
725 es->top=es->bottom=0; 705 es->top=es->bottom=0;
726 } 706 }
@@ -957,7 +937,7 @@ static unsigned long err_hash(const void *a_void)
957 { 937 {
958 unsigned long ret,l; 938 unsigned long ret,l;
959 939
960 l=((const ERR_STRING_DATA *)a_void)->error; 940 l=((ERR_STRING_DATA *)a_void)->error;
961 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); 941 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
962 return(ret^ret%19*13); 942 return(ret^ret%19*13);
963 } 943 }
@@ -965,21 +945,21 @@ static unsigned long err_hash(const void *a_void)
965/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */ 945/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */
966static int err_cmp(const void *a_void, const void *b_void) 946static int err_cmp(const void *a_void, const void *b_void)
967 { 947 {
968 return((int)(((const ERR_STRING_DATA *)a_void)->error - 948 return((int)(((ERR_STRING_DATA *)a_void)->error -
969 ((const ERR_STRING_DATA *)b_void)->error)); 949 ((ERR_STRING_DATA *)b_void)->error));
970 } 950 }
971 951
972/* static unsigned long pid_hash(ERR_STATE *a) */ 952/* static unsigned long pid_hash(ERR_STATE *a) */
973static unsigned long pid_hash(const void *a_void) 953static unsigned long pid_hash(const void *a_void)
974 { 954 {
975 return(((const ERR_STATE *)a_void)->pid*13); 955 return(((ERR_STATE *)a_void)->pid*13);
976 } 956 }
977 957
978/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */ 958/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */
979static int pid_cmp(const void *a_void, const void *b_void) 959static int pid_cmp(const void *a_void, const void *b_void)
980 { 960 {
981 return((int)((long)((const ERR_STATE *)a_void)->pid - 961 return((int)((long)((ERR_STATE *)a_void)->pid -
982 (long)((const ERR_STATE *)b_void)->pid)); 962 (long)((ERR_STATE *)b_void)->pid));
983 } 963 }
984 964
985void ERR_remove_state(unsigned long pid) 965void ERR_remove_state(unsigned long pid)
@@ -1089,7 +1069,7 @@ void ERR_add_error_data(int num, ...)
1089 else 1069 else
1090 str=p; 1070 str=p;
1091 } 1071 }
1092 BUF_strlcat(str,a,(size_t)s+1); 1072 BUF_strlcat(str,a,s+1);
1093 } 1073 }
1094 } 1074 }
1095 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); 1075 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
@@ -1097,33 +1077,3 @@ void ERR_add_error_data(int num, ...)
1097err: 1077err:
1098 va_end(args); 1078 va_end(args);
1099 } 1079 }
1100
1101int 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
1112int 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 }