diff options
author | djm <> | 2010-10-01 22:59:01 +0000 |
---|---|---|
committer | djm <> | 2010-10-01 22:59:01 +0000 |
commit | fe047d8b632246cb2db3234a0a4f32e5c318857b (patch) | |
tree | 939b752540947d33507b3acc48d76a8bfb7c3dc3 /src/lib/libcrypto/err/err_prn.c | |
parent | 2ea67f4aa254b09ded62e6e14fc893bbe6381579 (diff) | |
download | openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.gz openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.tar.bz2 openbsd-fe047d8b632246cb2db3234a0a4f32e5c318857b.zip |
resolve conflicts, fix local changes
Diffstat (limited to 'src/lib/libcrypto/err/err_prn.c')
-rw-r--r-- | src/lib/libcrypto/err/err_prn.c | 77 |
1 files changed, 17 insertions, 60 deletions
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c index 4cdf342fa6..a0168ac8ed 100644 --- a/src/lib/libcrypto/err/err_prn.c +++ b/src/lib/libcrypto/err/err_prn.c | |||
@@ -72,21 +72,29 @@ void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), | |||
72 | const char *file,*data; | 72 | const char *file,*data; |
73 | int line,flags; | 73 | int line,flags; |
74 | unsigned long es; | 74 | unsigned long es; |
75 | CRYPTO_THREADID cur; | ||
75 | 76 | ||
76 | es=CRYPTO_thread_id(); | 77 | CRYPTO_THREADID_current(&cur); |
78 | es=CRYPTO_THREADID_hash(&cur); | ||
77 | while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) | 79 | while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) |
78 | { | 80 | { |
79 | ERR_error_string_n(l, buf, sizeof buf); | 81 | ERR_error_string_n(l, buf, sizeof buf); |
80 | BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf, | 82 | BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, buf, |
81 | file, line, (flags & ERR_TXT_STRING) ? data : ""); | 83 | file, line, (flags & ERR_TXT_STRING) ? data : ""); |
82 | cb(buf2, strlen(buf2), u); | 84 | if (cb(buf2, strlen(buf2), u) <= 0) |
85 | break; /* abort outputting the error report */ | ||
83 | } | 86 | } |
84 | } | 87 | } |
85 | 88 | ||
86 | #ifndef OPENSSL_NO_FP_API | 89 | #ifndef OPENSSL_NO_FP_API |
87 | static int print_fp(const char *str, size_t len, void *fp) | 90 | static int print_fp(const char *str, size_t len, void *fp) |
88 | { | 91 | { |
89 | return fwrite(str, 1, len, fp); | 92 | BIO bio; |
93 | |||
94 | BIO_set(&bio,BIO_s_file()); | ||
95 | BIO_set_fp(&bio,fp,BIO_NOCLOSE); | ||
96 | |||
97 | return BIO_printf(&bio, "%s", str); | ||
90 | } | 98 | } |
91 | void ERR_print_errors_fp(FILE *fp) | 99 | void ERR_print_errors_fp(FILE *fp) |
92 | { | 100 | { |
@@ -94,64 +102,13 @@ void ERR_print_errors_fp(FILE *fp) | |||
94 | } | 102 | } |
95 | #endif | 103 | #endif |
96 | 104 | ||
97 | void ERR_error_string_n(unsigned long e, char *buf, size_t len) | 105 | static int print_bio(const char *str, size_t len, void *bp) |
98 | { | 106 | { |
99 | char lsbuf[64], fsbuf[64], rsbuf[64]; | 107 | return BIO_write((BIO *)bp, str, len); |
100 | const char *ls,*fs,*rs; | ||
101 | unsigned long l,f,r; | ||
102 | |||
103 | l=ERR_GET_LIB(e); | ||
104 | f=ERR_GET_FUNC(e); | ||
105 | r=ERR_GET_REASON(e); | ||
106 | |||
107 | ls=ERR_lib_error_string(e); | ||
108 | fs=ERR_func_error_string(e); | ||
109 | rs=ERR_reason_error_string(e); | ||
110 | |||
111 | if (ls == NULL) | ||
112 | BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l); | ||
113 | if (fs == NULL) | ||
114 | BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f); | ||
115 | if (rs == NULL) | ||
116 | BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r); | ||
117 | |||
118 | BIO_snprintf(buf, len,"error:%08lX:%s:%s:%s", e, ls?ls:lsbuf, | ||
119 | fs?fs:fsbuf, rs?rs:rsbuf); | ||
120 | if (strlen(buf) == len-1) | ||
121 | { | ||
122 | /* output may be truncated; make sure we always have 5 | ||
123 | * colon-separated fields, i.e. 4 colons ... */ | ||
124 | #define NUM_COLONS 4 | ||
125 | if (len > NUM_COLONS) /* ... if possible */ | ||
126 | { | ||
127 | int i; | ||
128 | char *s = buf; | ||
129 | |||
130 | for (i = 0; i < NUM_COLONS; i++) | ||
131 | { | ||
132 | char *colon = strchr(s, ':'); | ||
133 | if (colon == NULL || colon > &buf[len-1] - NUM_COLONS + i) | ||
134 | { | ||
135 | /* set colon no. i at last possible position | ||
136 | * (buf[len-1] is the terminating 0)*/ | ||
137 | colon = &buf[len-1] - NUM_COLONS + i; | ||
138 | *colon = ':'; | ||
139 | } | ||
140 | s = colon + 1; | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | } | 108 | } |
145 | 109 | void ERR_print_errors(BIO *bp) | |
146 | /* BAD for multi-threading: uses a local buffer if ret == NULL */ | ||
147 | /* ERR_error_string_n should be used instead for ret != NULL | ||
148 | * as ERR_error_string cannot know how large the buffer is */ | ||
149 | char *ERR_error_string(unsigned long e, char *ret) | ||
150 | { | 110 | { |
151 | static char buf[256]; | 111 | ERR_print_errors_cb(print_bio, bp); |
152 | |||
153 | if (ret == NULL) ret=buf; | ||
154 | ERR_error_string_n(e, ret, 256); | ||
155 | |||
156 | return ret; | ||
157 | } | 112 | } |
113 | |||
114 | |||