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.c185
1 files changed, 93 insertions, 92 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index 5aef6a1259..8810d838c6 100644
--- a/src/lib/libcrypto/err/err.c
+++ b/src/lib/libcrypto/err/err.c
@@ -57,34 +57,25 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "lhash.h" 60#include <stdarg.h>
61#include "crypto.h" 61#include <openssl/lhash.h>
62#include <openssl/crypto.h>
62#include "cryptlib.h" 63#include "cryptlib.h"
63#include "buffer.h" 64#include <openssl/buffer.h>
64#include "err.h" 65#include <openssl/err.h>
65#include "crypto.h" 66#include <openssl/crypto.h>
66 67
67 68
68static LHASH *error_hash=NULL; 69static LHASH *error_hash=NULL;
69static LHASH *thread_hash=NULL; 70static LHASH *thread_hash=NULL;
70 71
71#ifndef NOPROTO
72static unsigned long err_hash(ERR_STRING_DATA *a); 72static unsigned long err_hash(ERR_STRING_DATA *a);
73static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b); 73static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b);
74static unsigned long pid_hash(ERR_STATE *pid); 74static unsigned long pid_hash(ERR_STATE *pid);
75static int pid_cmp(ERR_STATE *a,ERR_STATE *pid); 75static int pid_cmp(ERR_STATE *a,ERR_STATE *pid);
76static unsigned long get_error_values(int inc,char **file,int *line, 76static unsigned long get_error_values(int inc,const char **file,int *line,
77 char **data,int *flags); 77 const char **data,int *flags);
78static void ERR_STATE_free(ERR_STATE *s); 78static void ERR_STATE_free(ERR_STATE *s);
79#else
80static unsigned long err_hash();
81static int err_cmp();
82static unsigned long pid_hash();
83static int pid_cmp();
84static void ERR_STATE_free();
85ERR_STATE *s;
86#endif
87
88#ifndef NO_ERR 79#ifndef NO_ERR
89static ERR_STRING_DATA ERR_str_libraries[]= 80static ERR_STRING_DATA ERR_str_libraries[]=
90 { 81 {
@@ -107,6 +98,8 @@ static ERR_STRING_DATA ERR_str_libraries[]=
107{ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"}, 98{ERR_PACK(ERR_LIB_PROXY,0,0) ,"Proxy routines"},
108{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"}, 99{ERR_PACK(ERR_LIB_BIO,0,0) ,"BIO routines"},
109{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"}, 100{ERR_PACK(ERR_LIB_PKCS7,0,0) ,"PKCS7 routines"},
101{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
102{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
110{0,NULL}, 103{0,NULL},
111 }; 104 };
112 105
@@ -123,6 +116,7 @@ static ERR_STRING_DATA ERR_str_functs[]=
123#ifdef WINDOWS 116#ifdef WINDOWS
124 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"}, 117 {ERR_PACK(0,SYS_F_WSASTARTUP,0), "WSAstartup"},
125#endif 118#endif
119 {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
126 {0,NULL}, 120 {0,NULL},
127 }; 121 };
128 122
@@ -146,8 +140,17 @@ static ERR_STRING_DATA ERR_str_reasons[]=
146{ERR_R_PROXY_LIB ,"PROXY lib"}, 140{ERR_R_PROXY_LIB ,"PROXY lib"},
147{ERR_R_BIO_LIB ,"BIO lib"}, 141{ERR_R_BIO_LIB ,"BIO lib"},
148{ERR_R_PKCS7_LIB ,"PKCS7 lib"}, 142{ERR_R_PKCS7_LIB ,"PKCS7 lib"},
143{ERR_R_PKCS12_LIB ,"PKCS12 lib"},
149{ERR_R_MALLOC_FAILURE ,"Malloc failure"}, 144{ERR_R_MALLOC_FAILURE ,"Malloc failure"},
150{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a fuction you should not call"}, 145{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
146{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
147{ERR_R_NESTED_ASN1_ERROR ,"nested asn1 error"},
148{ERR_R_BAD_ASN1_OBJECT_HEADER ,"bad asn1 object header"},
149{ERR_R_BAD_GET_ASN1_OBJECT_CALL ,"bad get asn1 object call"},
150{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
151{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
152{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
153
151{0,NULL}, 154{0,NULL},
152 }; 155 };
153#endif 156#endif
@@ -161,11 +164,13 @@ static ERR_STRING_DATA ERR_str_reasons[]=
161 } \ 164 } \
162 (p)->err_data_flags[i]=0; 165 (p)->err_data_flags[i]=0;
163 166
164static void ERR_STATE_free(s) 167static void ERR_STATE_free(ERR_STATE *s)
165ERR_STATE *s;
166 { 168 {
167 int i; 169 int i;
168 170
171 if(s == NULL)
172 return;
173
169 for (i=0; i<ERR_NUM_ERRORS; i++) 174 for (i=0; i<ERR_NUM_ERRORS; i++)
170 { 175 {
171 err_clear_data(s,i); 176 err_clear_data(s,i);
@@ -173,7 +178,7 @@ ERR_STATE *s;
173 Free(s); 178 Free(s);
174 } 179 }
175 180
176void ERR_load_ERR_strings() 181void ERR_load_ERR_strings(void)
177 { 182 {
178 static int init=1; 183 static int init=1;
179 184
@@ -196,9 +201,7 @@ void ERR_load_ERR_strings()
196 } 201 }
197 } 202 }
198 203
199void ERR_load_strings(lib,str) 204void ERR_load_strings(int lib, ERR_STRING_DATA *str)
200int lib;
201ERR_STRING_DATA *str;
202 { 205 {
203 if (error_hash == NULL) 206 if (error_hash == NULL)
204 { 207 {
@@ -224,7 +227,7 @@ ERR_STRING_DATA *str;
224 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH); 227 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
225 } 228 }
226 229
227void ERR_free_strings() 230void ERR_free_strings(void)
228 { 231 {
229 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 232 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
230 233
@@ -239,13 +242,30 @@ void ERR_free_strings()
239 242
240/********************************************************/ 243/********************************************************/
241 244
242void ERR_put_error(lib,func,reason,file,line) 245void ERR_put_error(int lib, int func, int reason, const char *file,
243int lib,func,reason; 246 int line)
244char *file;
245int line;
246 { 247 {
247 ERR_STATE *es; 248 ERR_STATE *es;
248 249
250#ifdef _OSD_POSIX
251 /* In the BS2000-OSD POSIX subsystem, the compiler generates
252 * path names in the form "*POSIX(/etc/passwd)".
253 * This dirty hack strips them to something sensible.
254 * @@@ We shouldn't modify a const string, though.
255 */
256 if (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
257 char *end;
258
259 /* Skip the "*POSIX(" prefix */
260 file += sizeof("*POSIX(")-1;
261 end = &file[strlen(file)-1];
262 if (*end == ')')
263 *end = '\0';
264 /* Optional: use the basename of the path only. */
265 if ((end = strrchr(file, '/')) != NULL)
266 file = &end[1];
267 }
268#endif
249 es=ERR_get_state(); 269 es=ERR_get_state();
250 270
251 es->top=(es->top+1)%ERR_NUM_ERRORS; 271 es->top=(es->top+1)%ERR_NUM_ERRORS;
@@ -257,7 +277,7 @@ int line;
257 err_clear_data(es,es->top); 277 err_clear_data(es,es->top);
258 } 278 }
259 279
260void ERR_clear_error() 280void ERR_clear_error(void)
261 { 281 {
262 ERR_STATE *es; 282 ERR_STATE *es;
263 283
@@ -277,42 +297,32 @@ void ERR_clear_error()
277 } 297 }
278 298
279 299
280unsigned long ERR_get_error() 300unsigned long ERR_get_error(void)
281 { return(get_error_values(1,NULL,NULL,NULL,NULL)); } 301 { return(get_error_values(1,NULL,NULL,NULL,NULL)); }
282 302
283unsigned long ERR_get_error_line(file,line) 303unsigned long ERR_get_error_line(const char **file,
284char **file; 304 int *line)
285int *line;
286 { return(get_error_values(1,file,line,NULL,NULL)); } 305 { return(get_error_values(1,file,line,NULL,NULL)); }
287 306
288unsigned long ERR_get_error_line_data(file,line,data,flags) 307unsigned long ERR_get_error_line_data(const char **file, int *line,
289char **file; 308 const char **data, int *flags)
290int *line; 309 { return(get_error_values(1,file,line,
291char **data; 310 data,flags)); }
292int *flags;
293 { return(get_error_values(1,file,line,data,flags)); }
294 311
295unsigned long ERR_peek_error() 312unsigned long ERR_peek_error(void)
296 { return(get_error_values(0,NULL,NULL,NULL,NULL)); } 313 { return(get_error_values(0,NULL,NULL,NULL,NULL)); }
297 314
298unsigned long ERR_peek_error_line(file,line) 315unsigned long ERR_peek_error_line(const char **file,
299char **file; 316 int *line)
300int *line;
301 { return(get_error_values(0,file,line,NULL,NULL)); } 317 { return(get_error_values(0,file,line,NULL,NULL)); }
302 318
303unsigned long ERR_peek_error_line_data(file,line,data,flags) 319unsigned long ERR_peek_error_line_data(const char **file, int *line,
304char **file; 320 const char **data, int *flags)
305int *line; 321 { return(get_error_values(0,file,line,
306char **data; 322 data,flags)); }
307int *flags; 323
308 { return(get_error_values(0,file,line,data,flags)); } 324static unsigned long get_error_values(int inc, const char **file, int *line,
309 325 const char **data, int *flags)
310static unsigned long get_error_values(inc,file,line,data,flags)
311int inc;
312char **file;
313int *line;
314char **data;
315int *flags;
316 { 326 {
317 int i=0; 327 int i=0;
318 ERR_STATE *es; 328 ERR_STATE *es;
@@ -361,12 +371,10 @@ int *flags;
361 } 371 }
362 372
363/* BAD for multi-threaded, uses a local buffer if ret == NULL */ 373/* BAD for multi-threaded, uses a local buffer if ret == NULL */
364char *ERR_error_string(e,ret) 374char *ERR_error_string(unsigned long e, char *ret)
365unsigned long e;
366char *ret;
367 { 375 {
368 static char buf[256]; 376 static char buf[256];
369 char *ls,*fs,*rs; 377 const char *ls,*fs,*rs;
370 unsigned long l,f,r; 378 unsigned long l,f,r;
371 int i; 379 int i;
372 380
@@ -397,18 +405,17 @@ char *ret;
397 return(ret); 405 return(ret);
398 } 406 }
399 407
400LHASH *ERR_get_string_table() 408LHASH *ERR_get_string_table(void)
401 { 409 {
402 return(error_hash); 410 return(error_hash);
403 } 411 }
404 412
405LHASH *ERR_get_err_state_table() 413LHASH *ERR_get_err_state_table(void)
406 { 414 {
407 return(thread_hash); 415 return(thread_hash);
408 } 416 }
409 417
410char *ERR_lib_error_string(e) 418const char *ERR_lib_error_string(unsigned long e)
411unsigned long e;
412 { 419 {
413 ERR_STRING_DATA d,*p=NULL; 420 ERR_STRING_DATA d,*p=NULL;
414 unsigned long l; 421 unsigned long l;
@@ -428,8 +435,7 @@ unsigned long e;
428 return((p == NULL)?NULL:p->string); 435 return((p == NULL)?NULL:p->string);
429 } 436 }
430 437
431char *ERR_func_error_string(e) 438const char *ERR_func_error_string(unsigned long e)
432unsigned long e;
433 { 439 {
434 ERR_STRING_DATA d,*p=NULL; 440 ERR_STRING_DATA d,*p=NULL;
435 unsigned long l,f; 441 unsigned long l,f;
@@ -450,8 +456,7 @@ unsigned long e;
450 return((p == NULL)?NULL:p->string); 456 return((p == NULL)?NULL:p->string);
451 } 457 }
452 458
453char *ERR_reason_error_string(e) 459const char *ERR_reason_error_string(unsigned long e)
454unsigned long e;
455 { 460 {
456 ERR_STRING_DATA d,*p=NULL; 461 ERR_STRING_DATA d,*p=NULL;
457 unsigned long l,r; 462 unsigned long l,r;
@@ -478,8 +483,7 @@ unsigned long e;
478 return((p == NULL)?NULL:p->string); 483 return((p == NULL)?NULL:p->string);
479 } 484 }
480 485
481static unsigned long err_hash(a) 486static unsigned long err_hash(ERR_STRING_DATA *a)
482ERR_STRING_DATA *a;
483 { 487 {
484 unsigned long ret,l; 488 unsigned long ret,l;
485 489
@@ -488,26 +492,22 @@ ERR_STRING_DATA *a;
488 return(ret^ret%19*13); 492 return(ret^ret%19*13);
489 } 493 }
490 494
491static int err_cmp(a,b) 495static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b)
492ERR_STRING_DATA *a,*b;
493 { 496 {
494 return((int)(a->error-b->error)); 497 return((int)(a->error-b->error));
495 } 498 }
496 499
497static unsigned long pid_hash(a) 500static unsigned long pid_hash(ERR_STATE *a)
498ERR_STATE *a;
499 { 501 {
500 return(a->pid*13); 502 return(a->pid*13);
501 } 503 }
502 504
503static int pid_cmp(a,b) 505static int pid_cmp(ERR_STATE *a, ERR_STATE *b)
504ERR_STATE *a,*b;
505 { 506 {
506 return((int)((long)a->pid - (long)b->pid)); 507 return((int)((long)a->pid - (long)b->pid));
507 } 508 }
508 509
509void ERR_remove_state(pid) 510void ERR_remove_state(unsigned long pid)
510unsigned long pid;
511 { 511 {
512 ERR_STATE *p,tmp; 512 ERR_STATE *p,tmp;
513 513
@@ -523,7 +523,7 @@ unsigned long pid;
523 if (p != NULL) ERR_STATE_free(p); 523 if (p != NULL) ERR_STATE_free(p);
524 } 524 }
525 525
526ERR_STATE *ERR_get_state() 526ERR_STATE *ERR_get_state(void)
527 { 527 {
528 static ERR_STATE fallback; 528 static ERR_STATE fallback;
529 ERR_STATE *ret=NULL,tmp,*tmpp; 529 ERR_STATE *ret=NULL,tmp,*tmpp;
@@ -539,7 +539,9 @@ ERR_STATE *ERR_get_state()
539 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 539 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
540 if (thread_hash == NULL) 540 if (thread_hash == NULL)
541 { 541 {
542 MemCheck_off();
542 thread_hash=lh_new(pid_hash,pid_cmp); 543 thread_hash=lh_new(pid_hash,pid_cmp);
544 MemCheck_on();
543 CRYPTO_w_unlock(CRYPTO_LOCK_ERR); 545 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
544 if (thread_hash == NULL) return(&fallback); 546 if (thread_hash == NULL) return(&fallback);
545 } 547 }
@@ -577,16 +579,14 @@ ERR_STATE *ERR_get_state()
577 return(ret); 579 return(ret);
578 } 580 }
579 581
580int ERR_get_next_error_library() 582int ERR_get_next_error_library(void)
581 { 583 {
582 static int value=ERR_LIB_USER; 584 static int value=ERR_LIB_USER;
583 585
584 return(value++); 586 return(value++);
585 } 587 }
586 588
587void ERR_set_error_data(data,flags) 589void ERR_set_error_data(char *data, int flags)
588char *data;
589int flags;
590 { 590 {
591 ERR_STATE *es; 591 ERR_STATE *es;
592 int i; 592 int i;
@@ -601,10 +601,9 @@ int flags;
601 es->err_data_flags[es->top]=flags; 601 es->err_data_flags[es->top]=flags;
602 } 602 }
603 603
604void ERR_add_error_data( VAR_PLIST(int , num)) 604void ERR_add_error_data(int num, ...)
605VAR_ALIST 605 {
606 { 606 va_list args;
607 VAR_BDEFN(args, int, num);
608 int i,n,s; 607 int i,n,s;
609 char *str,*p,*a; 608 char *str,*p,*a;
610 609
@@ -613,12 +612,14 @@ VAR_ALIST
613 if (str == NULL) return; 612 if (str == NULL) return;
614 str[0]='\0'; 613 str[0]='\0';
615 614
616 VAR_INIT(args,int,num); 615 va_start(args, num);
617 n=0; 616 n=0;
618 for (i=0; i<num; i++) 617 for (i=0; i<num; i++)
619 { 618 {
620 VAR_ARG(args,char *,a); 619 a=va_arg(args, char*);
621 if (a != NULL) { 620 /* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
621 if (a != NULL)
622 {
622 n+=strlen(a); 623 n+=strlen(a);
623 if (n > s) 624 if (n > s)
624 { 625 {
@@ -637,6 +638,6 @@ VAR_ALIST
637 } 638 }
638 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); 639 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
639 640
640 VAR_END( args ); 641 va_end(args);
641 } 642 }
642 643