summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/err
diff options
context:
space:
mode:
authorbeck <>2000-12-15 02:58:47 +0000
committerbeck <>2000-12-15 02:58:47 +0000
commit9200bb13d15da4b2a23e6bc92c20e95b74aa2113 (patch)
tree5c52d628ec1e34be76e7ef2a4235d248b7c44d24 /src/lib/libcrypto/err
parente131d25072e3d4197ba4b9bcc0d1b27d34d6488d (diff)
downloadopenbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.gz
openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.bz2
openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.zip
openssl-engine-0.9.6 merge
Diffstat (limited to 'src/lib/libcrypto/err')
-rw-r--r--src/lib/libcrypto/err/Makefile.ssl33
-rw-r--r--src/lib/libcrypto/err/err.c154
-rw-r--r--src/lib/libcrypto/err/err.h37
-rw-r--r--src/lib/libcrypto/err/err_all.c4
-rw-r--r--src/lib/libcrypto/err/err_prn.c6
-rw-r--r--src/lib/libcrypto/err/openssl.ec2
6 files changed, 155 insertions, 81 deletions
diff --git a/src/lib/libcrypto/err/Makefile.ssl b/src/lib/libcrypto/err/Makefile.ssl
index fb74e4eb13..cf94f406e4 100644
--- a/src/lib/libcrypto/err/Makefile.ssl
+++ b/src/lib/libcrypto/err/Makefile.ssl
@@ -83,24 +83,28 @@ err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
83err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 83err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 84err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
85err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 85err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
86err.o: ../../include/openssl/stack.h ../cryptlib.h 86err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
87err.o: ../cryptlib.h
87err_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h 88err_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
88err_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h 89err_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
89err_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h 90err_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
90err_all.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h 91err_all.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
91err_all.o: ../../include/openssl/des.h ../../include/openssl/dh.h 92err_all.o: ../../include/openssl/des.h ../../include/openssl/dh.h
92err_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h 93err_all.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
93err_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h 94err_all.o: ../../include/openssl/e_os.h ../../include/openssl/e_os2.h
94err_all.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h 95err_all.o: ../../include/openssl/engine.h ../../include/openssl/err.h
95err_all.o: ../../include/openssl/md2.h ../../include/openssl/md5.h 96err_all.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
96err_all.o: ../../include/openssl/mdc2.h ../../include/openssl/objects.h 97err_all.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
97err_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h 98err_all.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
98err_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h 99err_all.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
99err_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h 100err_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
100err_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h 101err_all.o: ../../include/openssl/opensslv.h ../../include/openssl/pem2.h
101err_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h 102err_all.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
102err_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h 103err_all.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
103err_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h 104err_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
105err_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
106err_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
107err_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
104err_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h 108err_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
105err_all.o: ../../include/openssl/x509v3.h 109err_all.o: ../../include/openssl/x509v3.h
106err_prn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h 110err_prn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
@@ -108,4 +112,5 @@ err_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os.h
108err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h 112err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
109err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h 113err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
110err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h 114err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
111err_prn.o: ../../include/openssl/stack.h ../cryptlib.h 115err_prn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
116err_prn.o: ../cryptlib.h
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index eb8c76aa0b..99272e437c 100644
--- a/src/lib/libcrypto/err/err.c
+++ b/src/lib/libcrypto/err/err.c
@@ -116,8 +116,8 @@
116#include <openssl/crypto.h> 116#include <openssl/crypto.h>
117#include "cryptlib.h" 117#include "cryptlib.h"
118#include <openssl/buffer.h> 118#include <openssl/buffer.h>
119#include <openssl/bio.h>
119#include <openssl/err.h> 120#include <openssl/err.h>
120#include <openssl/crypto.h>
121 121
122 122
123static LHASH *error_hash=NULL; 123static LHASH *error_hash=NULL;
@@ -137,6 +137,7 @@ static ERR_STRING_DATA ERR_str_libraries[]=
137{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"}, 137{ERR_PACK(ERR_LIB_SYS,0,0) ,"system library"},
138{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"}, 138{ERR_PACK(ERR_LIB_BN,0,0) ,"bignum routines"},
139{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"}, 139{ERR_PACK(ERR_LIB_RSA,0,0) ,"rsa routines"},
140{ERR_PACK(ERR_LIB_DSA,0,0) ,"dsa routines"},
140{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"}, 141{ERR_PACK(ERR_LIB_DH,0,0) ,"Diffie-Hellman routines"},
141{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"}, 142{ERR_PACK(ERR_LIB_EVP,0,0) ,"digital envelope routines"},
142{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"}, 143{ERR_PACK(ERR_LIB_BUF,0,0) ,"memory buffer routines"},
@@ -155,6 +156,8 @@ static ERR_STRING_DATA ERR_str_libraries[]=
155{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"}, 156{ERR_PACK(ERR_LIB_X509V3,0,0) ,"X509 V3 routines"},
156{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"}, 157{ERR_PACK(ERR_LIB_PKCS12,0,0) ,"PKCS12 routines"},
157{ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"}, 158{ERR_PACK(ERR_LIB_RAND,0,0) ,"random number generator"},
159{ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"},
160{ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"},
158{0,NULL}, 161{0,NULL},
159 }; 162 };
160 163
@@ -205,6 +208,8 @@ static ERR_STRING_DATA ERR_str_reasons[]=
205{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"}, 208{ERR_R_EXPECTING_AN_ASN1_SEQUENCE ,"expecting an asn1 sequence"},
206{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"}, 209{ERR_R_ASN1_LENGTH_MISMATCH ,"asn1 length mismatch"},
207{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"}, 210{ERR_R_MISSING_ASN1_EOS ,"missing asn1 eos"},
211{ERR_R_DSO_LIB ,"DSO lib"},
212{ERR_R_ENGINE_LIB ,"ENGINE lib"},
208 213
209{0,NULL}, 214{0,NULL},
210 }; 215 };
@@ -225,7 +230,7 @@ static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
225 230
226static void build_SYS_str_reasons() 231static void build_SYS_str_reasons()
227 { 232 {
228 /* Malloc cannot be used here, use static storage instead */ 233 /* OPENSSL_malloc cannot be used here, use static storage instead */
229 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; 234 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
230 int i; 235 int i;
231 236
@@ -262,7 +267,7 @@ static void build_SYS_str_reasons()
262 if (((p)->err_data[i] != NULL) && \ 267 if (((p)->err_data[i] != NULL) && \
263 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ 268 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
264 { \ 269 { \
265 Free((p)->err_data[i]); \ 270 OPENSSL_free((p)->err_data[i]); \
266 (p)->err_data[i]=NULL; \ 271 (p)->err_data[i]=NULL; \
267 } \ 272 } \
268 (p)->err_data_flags[i]=0; 273 (p)->err_data_flags[i]=0;
@@ -278,7 +283,7 @@ static void ERR_STATE_free(ERR_STATE *s)
278 { 283 {
279 err_clear_data(s,i); 284 err_clear_data(s,i);
280 } 285 }
281 Free(s); 286 OPENSSL_free(s);
282 } 287 }
283 288
284void ERR_load_ERR_strings(void) 289void ERR_load_ERR_strings(void)
@@ -475,13 +480,11 @@ static unsigned long get_error_values(int inc, const char **file, int *line,
475 return(ret); 480 return(ret);
476 } 481 }
477 482
478/* BAD for multi-threaded, uses a local buffer if ret == NULL */ 483void ERR_error_string_n(unsigned long e, char *buf, size_t len)
479char *ERR_error_string(unsigned long e, char *ret)
480 { 484 {
481 static char buf[256]; 485 char lsbuf[64], fsbuf[64], rsbuf[64];
482 const char *ls,*fs,*rs; 486 const char *ls,*fs,*rs;
483 unsigned long l,f,r; 487 unsigned long l,f,r;
484 int i;
485 488
486 l=ERR_GET_LIB(e); 489 l=ERR_GET_LIB(e);
487 f=ERR_GET_FUNC(e); 490 f=ERR_GET_FUNC(e);
@@ -491,21 +494,50 @@ char *ERR_error_string(unsigned long e, char *ret)
491 fs=ERR_func_error_string(e); 494 fs=ERR_func_error_string(e);
492 rs=ERR_reason_error_string(e); 495 rs=ERR_reason_error_string(e);
493 496
494 if (ret == NULL) ret=buf; 497 if (ls == NULL)
495 498 BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l);
496 sprintf(&(ret[0]),"error:%08lX:",e);
497 i=strlen(ret);
498 if (ls == NULL)
499 sprintf(&(ret[i]),":lib(%lu) ",l);
500 else sprintf(&(ret[i]),"%s",ls);
501 i=strlen(ret);
502 if (fs == NULL) 499 if (fs == NULL)
503 sprintf(&(ret[i]),":func(%lu) ",f); 500 BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f);
504 else sprintf(&(ret[i]),":%s",fs);
505 i=strlen(ret);
506 if (rs == NULL) 501 if (rs == NULL)
507 sprintf(&(ret[i]),":reason(%lu)",r); 502 BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
508 else sprintf(&(ret[i]),":%s",rs); 503
504 BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf,
505 fs?fs:fsbuf, rs?rs:rsbuf);
506 if (strlen(buf) == len-1)
507 {
508 /* output may be truncated; make sure we always have 5
509 * colon-separated fields, i.e. 4 colons ... */
510#define NUM_COLONS 4
511 if (len > NUM_COLONS) /* ... if possible */
512 {
513 int i;
514 char *s = buf;
515
516 for (i = 0; i < NUM_COLONS; i++)
517 {
518 char *colon = strchr(s, ':');
519 if (colon == NULL || colon > &buf[len-1] - NUM_COLONS + i)
520 {
521 /* set colon no. i at last possible position
522 * (buf[len-1] is the terminating 0)*/
523 colon = &buf[len-1] - NUM_COLONS + i;
524 *colon = ':';
525 }
526 s = colon + 1;
527 }
528 }
529 }
530 }
531
532/* BAD for multi-threading: uses a local buffer if ret == NULL */
533/* ERR_error_string_n should be used instead for ret != NULL
534 * as ERR_error_string cannot know how large the buffer is */
535char *ERR_error_string(unsigned long e, char *ret)
536 {
537 static char buf[256];
538
539 if (ret == NULL) ret=buf;
540 ERR_error_string_n(e, ret, 256);
509 541
510 return(ret); 542 return(ret);
511 } 543 }
@@ -515,6 +547,7 @@ LHASH *ERR_get_string_table(void)
515 return(error_hash); 547 return(error_hash);
516 } 548 }
517 549
550/* not thread-safe */
518LHASH *ERR_get_err_state_table(void) 551LHASH *ERR_get_err_state_table(void)
519 { 552 {
520 return(thread_hash); 553 return(thread_hash);
@@ -527,7 +560,7 @@ const char *ERR_lib_error_string(unsigned long e)
527 560
528 l=ERR_GET_LIB(e); 561 l=ERR_GET_LIB(e);
529 562
530 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH); 563 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
531 564
532 if (error_hash != NULL) 565 if (error_hash != NULL)
533 { 566 {
@@ -535,7 +568,7 @@ const char *ERR_lib_error_string(unsigned long e)
535 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d); 568 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
536 } 569 }
537 570
538 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH); 571 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
539 572
540 return((p == NULL)?NULL:p->string); 573 return((p == NULL)?NULL:p->string);
541 } 574 }
@@ -548,7 +581,7 @@ const char *ERR_func_error_string(unsigned long e)
548 l=ERR_GET_LIB(e); 581 l=ERR_GET_LIB(e);
549 f=ERR_GET_FUNC(e); 582 f=ERR_GET_FUNC(e);
550 583
551 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH); 584 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
552 585
553 if (error_hash != NULL) 586 if (error_hash != NULL)
554 { 587 {
@@ -556,7 +589,7 @@ const char *ERR_func_error_string(unsigned long e)
556 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d); 589 p=(ERR_STRING_DATA *)lh_retrieve(error_hash,&d);
557 } 590 }
558 591
559 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH); 592 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
560 593
561 return((p == NULL)?NULL:p->string); 594 return((p == NULL)?NULL:p->string);
562 } 595 }
@@ -569,7 +602,7 @@ const char *ERR_reason_error_string(unsigned long e)
569 l=ERR_GET_LIB(e); 602 l=ERR_GET_LIB(e);
570 r=ERR_GET_REASON(e); 603 r=ERR_GET_REASON(e);
571 604
572 CRYPTO_r_lock(CRYPTO_LOCK_ERR_HASH); 605 CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
573 606
574 if (error_hash != NULL) 607 if (error_hash != NULL)
575 { 608 {
@@ -582,7 +615,7 @@ const char *ERR_reason_error_string(unsigned long e)
582 } 615 }
583 } 616 }
584 617
585 CRYPTO_r_unlock(CRYPTO_LOCK_ERR_HASH); 618 CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
586 619
587 return((p == NULL)?NULL:p->string); 620 return((p == NULL)?NULL:p->string);
588 } 621 }
@@ -613,7 +646,7 @@ static int pid_cmp(ERR_STATE *a, ERR_STATE *b)
613 646
614void ERR_remove_state(unsigned long pid) 647void ERR_remove_state(unsigned long pid)
615 { 648 {
616 ERR_STATE *p,tmp; 649 ERR_STATE *p = NULL,tmp;
617 650
618 if (thread_hash == NULL) 651 if (thread_hash == NULL)
619 return; 652 return;
@@ -621,7 +654,16 @@ void ERR_remove_state(unsigned long pid)
621 pid=(unsigned long)CRYPTO_thread_id(); 654 pid=(unsigned long)CRYPTO_thread_id();
622 tmp.pid=pid; 655 tmp.pid=pid;
623 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 656 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
624 p=(ERR_STATE *)lh_delete(thread_hash,&tmp); 657 if (thread_hash)
658 {
659 p=(ERR_STATE *)lh_delete(thread_hash,&tmp);
660 if (lh_num_items(thread_hash) == 0)
661 {
662 /* make sure we don't leak memory */
663 lh_free(thread_hash);
664 thread_hash = NULL;
665 }
666 }
625 CRYPTO_w_unlock(CRYPTO_LOCK_ERR); 667 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
626 668
627 if (p != NULL) ERR_STATE_free(p); 669 if (p != NULL) ERR_STATE_free(p);
@@ -630,39 +672,25 @@ void ERR_remove_state(unsigned long pid)
630ERR_STATE *ERR_get_state(void) 672ERR_STATE *ERR_get_state(void)
631 { 673 {
632 static ERR_STATE fallback; 674 static ERR_STATE fallback;
633 ERR_STATE *ret=NULL,tmp,*tmpp; 675 ERR_STATE *ret=NULL,tmp,*tmpp=NULL;
676 int thread_state_exists;
634 int i; 677 int i;
635 unsigned long pid; 678 unsigned long pid;
636 679
637 pid=(unsigned long)CRYPTO_thread_id(); 680 pid=(unsigned long)CRYPTO_thread_id();
638 681
639 CRYPTO_r_lock(CRYPTO_LOCK_ERR); 682 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
640 if (thread_hash == NULL) 683 if (thread_hash != NULL)
641 {
642 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
643 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
644 if (thread_hash == NULL)
645 {
646 MemCheck_off();
647 thread_hash=lh_new(pid_hash,pid_cmp);
648 MemCheck_on();
649 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
650 if (thread_hash == NULL) return(&fallback);
651 }
652 else
653 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
654 }
655 else
656 { 684 {
657 tmp.pid=pid; 685 tmp.pid=pid;
658 ret=(ERR_STATE *)lh_retrieve(thread_hash,&tmp); 686 ret=(ERR_STATE *)lh_retrieve(thread_hash,&tmp);
659 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
660 } 687 }
688 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
661 689
662 /* ret == the error state, if NULL, make a new one */ 690 /* ret == the error state, if NULL, make a new one */
663 if (ret == NULL) 691 if (ret == NULL)
664 { 692 {
665 ret=(ERR_STATE *)Malloc(sizeof(ERR_STATE)); 693 ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
666 if (ret == NULL) return(&fallback); 694 if (ret == NULL) return(&fallback);
667 ret->pid=pid; 695 ret->pid=pid;
668 ret->top=0; 696 ret->top=0;
@@ -672,9 +700,29 @@ ERR_STATE *ERR_get_state(void)
672 ret->err_data[i]=NULL; 700 ret->err_data[i]=NULL;
673 ret->err_data_flags[i]=0; 701 ret->err_data_flags[i]=0;
674 } 702 }
703
675 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 704 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
676 tmpp=(ERR_STATE *)lh_insert(thread_hash,ret); 705
706 /* no entry yet in thread_hash for current thread -
707 * thus, it may have changed since we last looked at it */
708 if (thread_hash == NULL)
709 thread_hash = lh_new(pid_hash, pid_cmp);
710 if (thread_hash == NULL)
711 thread_state_exists = 0; /* allocation error */
712 else
713 {
714 tmpp=(ERR_STATE *)lh_insert(thread_hash,ret);
715 thread_state_exists = 1;
716 }
717
677 CRYPTO_w_unlock(CRYPTO_LOCK_ERR); 718 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
719
720 if (!thread_state_exists)
721 {
722 ERR_STATE_free(ret); /* could not insert it */
723 return(&fallback);
724 }
725
678 if (tmpp != NULL) /* old entry - should not happen */ 726 if (tmpp != NULL) /* old entry - should not happen */
679 { 727 {
680 ERR_STATE_free(tmpp); 728 ERR_STATE_free(tmpp);
@@ -712,7 +760,7 @@ void ERR_add_error_data(int num, ...)
712 char *str,*p,*a; 760 char *str,*p,*a;
713 761
714 s=64; 762 s=64;
715 str=Malloc(s+1); 763 str=OPENSSL_malloc(s+1);
716 if (str == NULL) return; 764 if (str == NULL) return;
717 str[0]='\0'; 765 str[0]='\0';
718 766
@@ -728,10 +776,10 @@ void ERR_add_error_data(int num, ...)
728 if (n > s) 776 if (n > s)
729 { 777 {
730 s=n+20; 778 s=n+20;
731 p=Realloc(str,s+1); 779 p=OPENSSL_realloc(str,s+1);
732 if (p == NULL) 780 if (p == NULL)
733 { 781 {
734 Free(str); 782 OPENSSL_free(str);
735 return; 783 return;
736 } 784 }
737 else 785 else
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h
index 15bafbff43..7388a4a937 100644
--- a/src/lib/libcrypto/err/err.h
+++ b/src/lib/libcrypto/err/err.h
@@ -59,12 +59,20 @@
59#ifndef HEADER_ERR_H 59#ifndef HEADER_ERR_H
60#define HEADER_ERR_H 60#define HEADER_ERR_H
61 61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifndef NO_FP_API 62#ifndef NO_FP_API
67#include <stdio.h> 63#include <stdio.h>
64#include <stdlib.h>
65#endif
66
67#ifndef NO_BIO
68#include <openssl/bio.h>
69#endif
70#ifndef NO_LHASH
71#include <openssl/lhash.h>
72#endif
73
74#ifdef __cplusplus
75extern "C" {
68#endif 76#endif
69 77
70/* The following is a bit of a trick to help the object files only contain 78/* The following is a bit of a trick to help the object files only contain
@@ -123,6 +131,8 @@ typedef struct err_state_st
123#define ERR_LIB_X509V3 34 131#define ERR_LIB_X509V3 34
124#define ERR_LIB_PKCS12 35 132#define ERR_LIB_PKCS12 35
125#define ERR_LIB_RAND 36 133#define ERR_LIB_RAND 36
134#define ERR_LIB_DSO 37
135#define ERR_LIB_ENGINE 38
126 136
127#define ERR_LIB_USER 128 137#define ERR_LIB_USER 128
128 138
@@ -151,6 +161,8 @@ typedef struct err_state_st
151#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__) 161#define X509V3err(f,r) ERR_PUT_error(ERR_LIB_X509V3,(f),(r),ERR_file_name,__LINE__)
152#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__) 162#define PKCS12err(f,r) ERR_PUT_error(ERR_LIB_PKCS12,(f),(r),ERR_file_name,__LINE__)
153#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),ERR_file_name,__LINE__) 163#define RANDerr(f,r) ERR_PUT_error(ERR_LIB_RAND,(f),(r),ERR_file_name,__LINE__)
164#define DSOerr(f,r) ERR_PUT_error(ERR_LIB_DSO,(f),(r),ERR_file_name,__LINE__)
165#define ENGINEerr(f,r) ERR_PUT_error(ERR_LIB_ENGINE,(f),(r),ERR_file_name,__LINE__)
154 166
155/* Borland C seems too stupid to be able to shift and do longs in 167/* Borland C seems too stupid to be able to shift and do longs in
156 * the pre-processor :-( */ 168 * the pre-processor :-( */
@@ -199,6 +211,8 @@ typedef struct err_state_st
199#define ERR_R_BIO_LIB ERR_LIB_BIO 211#define ERR_R_BIO_LIB ERR_LIB_BIO
200#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7 212#define ERR_R_PKCS7_LIB ERR_LIB_PKCS7
201#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12 213#define ERR_R_PKCS12_LIB ERR_LIB_PKCS12
214#define ERR_R_DSO_LIB ERR_LIB_DSO
215#define ERR_R_ENGINE_LIB ERR_LIB_ENGINE
202 216
203/* fatal error */ 217/* fatal error */
204#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL) 218#define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
@@ -230,13 +244,14 @@ unsigned long ERR_peek_error_line_data(const char **file,int *line,
230 const char **data,int *flags); 244 const char **data,int *flags);
231void ERR_clear_error(void ); 245void ERR_clear_error(void );
232char *ERR_error_string(unsigned long e,char *buf); 246char *ERR_error_string(unsigned long e,char *buf);
247void ERR_error_string_n(unsigned long e, char *buf, size_t len);
233const char *ERR_lib_error_string(unsigned long e); 248const char *ERR_lib_error_string(unsigned long e);
234const char *ERR_func_error_string(unsigned long e); 249const char *ERR_func_error_string(unsigned long e);
235const char *ERR_reason_error_string(unsigned long e); 250const char *ERR_reason_error_string(unsigned long e);
236#ifndef NO_FP_API 251#ifndef NO_FP_API
237void ERR_print_errors_fp(FILE *fp); 252void ERR_print_errors_fp(FILE *fp);
238#endif 253#endif
239#ifdef HEADER_BIO_H 254#ifndef NO_BIO
240void ERR_print_errors(BIO *bp); 255void ERR_print_errors(BIO *bp);
241void ERR_add_error_data(int num, ...); 256void ERR_add_error_data(int num, ...);
242#endif 257#endif
@@ -248,15 +263,13 @@ void ERR_free_strings(void);
248void ERR_remove_state(unsigned long pid); /* if zero we look it up */ 263void ERR_remove_state(unsigned long pid); /* if zero we look it up */
249ERR_STATE *ERR_get_state(void); 264ERR_STATE *ERR_get_state(void);
250 265
251#ifdef HEADER_LHASH_H 266#ifndef NO_LHASH
252LHASH *ERR_get_string_table(void ); 267LHASH *ERR_get_string_table(void);
253LHASH *ERR_get_err_state_table(void ); 268LHASH *ERR_get_err_state_table(void); /* even less thread-safe than
254#else 269 * ERR_get_string_table :-) */
255char *ERR_get_string_table(void );
256char *ERR_get_err_state_table(void );
257#endif 270#endif
258 271
259int ERR_get_next_error_library(void ); 272int ERR_get_next_error_library(void);
260 273
261#ifdef __cplusplus 274#ifdef __cplusplus
262} 275}
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
index 10c463b389..b8315d8272 100644
--- a/src/lib/libcrypto/err/err_all.c
+++ b/src/lib/libcrypto/err/err_all.c
@@ -81,6 +81,8 @@
81#include <openssl/conf.h> 81#include <openssl/conf.h>
82#include <openssl/pkcs12.h> 82#include <openssl/pkcs12.h>
83#include <openssl/rand.h> 83#include <openssl/rand.h>
84#include <openssl/dso.h>
85#include <openssl/engine.h>
84#include <openssl/err.h> 86#include <openssl/err.h>
85 87
86void ERR_load_crypto_strings(void) 88void ERR_load_crypto_strings(void)
@@ -118,5 +120,7 @@ void ERR_load_crypto_strings(void)
118 ERR_load_PKCS7_strings(); 120 ERR_load_PKCS7_strings();
119 ERR_load_PKCS12_strings(); 121 ERR_load_PKCS12_strings();
120 ERR_load_RAND_strings(); 122 ERR_load_RAND_strings();
123 ERR_load_DSO_strings();
124 ERR_load_ENGINE_strings();
121#endif 125#endif
122 } 126 }
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c
index 0999ff214b..6f60b016c3 100644
--- a/src/lib/libcrypto/err/err_prn.c
+++ b/src/lib/libcrypto/err/err_prn.c
@@ -76,7 +76,8 @@ void ERR_print_errors_fp(FILE *fp)
76 es=CRYPTO_thread_id(); 76 es=CRYPTO_thread_id();
77 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) 77 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
78 { 78 {
79 fprintf(fp,"%lu:%s:%s:%d:%s\n",es,ERR_error_string(l,buf), 79 ERR_error_string_n(l, buf, sizeof buf);
80 fprintf(fp,"%lu:%s:%s:%d:%s\n",es,buf,
80 file,line,(flags&ERR_TXT_STRING)?data:""); 81 file,line,(flags&ERR_TXT_STRING)?data:"");
81 } 82 }
82 } 83 }
@@ -94,7 +95,8 @@ void ERR_print_errors(BIO *bp)
94 es=CRYPTO_thread_id(); 95 es=CRYPTO_thread_id();
95 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) 96 while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0)
96 { 97 {
97 sprintf(buf2,"%lu:%s:%s:%d:",es,ERR_error_string(l,buf), 98 ERR_error_string_n(l, buf, sizeof buf);
99 sprintf(buf2,"%lu:%s:%s:%d:",es,buf,
98 file,line); 100 file,line);
99 BIO_write(bp,buf2,strlen(buf2)); 101 BIO_write(bp,buf2,strlen(buf2));
100 if (flags & ERR_TXT_STRING) 102 if (flags & ERR_TXT_STRING)
diff --git a/src/lib/libcrypto/err/openssl.ec b/src/lib/libcrypto/err/openssl.ec
index e132ba3182..861d680e07 100644
--- a/src/lib/libcrypto/err/openssl.ec
+++ b/src/lib/libcrypto/err/openssl.ec
@@ -3,6 +3,7 @@ L CRYPTO crypto/crypto.h crypto/cpt_err.c
3L BN crypto/bn/bn.h crypto/bn/bn_err.c 3L BN crypto/bn/bn.h crypto/bn/bn_err.c
4L RSA crypto/rsa/rsa.h crypto/rsa/rsa_err.c 4L RSA crypto/rsa/rsa.h crypto/rsa/rsa_err.c
5L DSA crypto/dsa/dsa.h crypto/dsa/dsa_err.c 5L DSA crypto/dsa/dsa.h crypto/dsa/dsa_err.c
6L DSO crypto/dso/dso.h crypto/dso/dso_err.c
6L DH crypto/dh/dh.h crypto/dh/dh_err.c 7L DH crypto/dh/dh.h crypto/dh/dh_err.c
7L EVP crypto/evp/evp.h crypto/evp/evp_err.c 8L EVP crypto/evp/evp.h crypto/evp/evp_err.c
8L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c 9L BUF crypto/buffer/buffer.h crypto/buffer/buf_err.c
@@ -22,6 +23,7 @@ L RSAREF rsaref/rsaref.h rsaref/rsar_err.c
22L SSL ssl/ssl.h ssl/ssl_err.c 23L SSL ssl/ssl.h ssl/ssl_err.c
23L COMP crypto/comp/comp.h crypto/comp/comp_err.c 24L COMP crypto/comp/comp.h crypto/comp/comp_err.c
24L RAND crypto/rand/rand.h crypto/rand/rand_err.c 25L RAND crypto/rand/rand.h crypto/rand/rand_err.c
26L ENGINE crypto/engine/engine.h crypto/engine/engine_err.c
25 27
26 28
27F RSAREF_F_RSA_BN2BIN 29F RSAREF_F_RSA_BN2BIN