diff options
author | djm <> | 2009-01-09 12:14:11 +0000 |
---|---|---|
committer | djm <> | 2009-01-09 12:14:11 +0000 |
commit | a0fdc9ec41594852f67ec77dfad9cb06bacc4186 (patch) | |
tree | c43f6b3a4d93ad2cb3dcf93275295679d895a033 /src/lib/libcrypto/err/err_prn.c | |
parent | 5a3c0a05c7f2c5d3c584b7c8d6aec836dd724c80 (diff) | |
download | openbsd-a0fdc9ec41594852f67ec77dfad9cb06bacc4186.tar.gz openbsd-a0fdc9ec41594852f67ec77dfad9cb06bacc4186.tar.bz2 openbsd-a0fdc9ec41594852f67ec77dfad9cb06bacc4186.zip |
import openssl-0.9.8j
Diffstat (limited to 'src/lib/libcrypto/err/err_prn.c')
-rw-r--r-- | src/lib/libcrypto/err/err_prn.c | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c index 2224a901e5..4cdf342fa6 100644 --- a/src/lib/libcrypto/err/err_prn.c +++ b/src/lib/libcrypto/err/err_prn.c | |||
@@ -86,12 +86,7 @@ void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), | |||
86 | #ifndef OPENSSL_NO_FP_API | 86 | #ifndef OPENSSL_NO_FP_API |
87 | static int print_fp(const char *str, size_t len, void *fp) | 87 | static int print_fp(const char *str, size_t len, void *fp) |
88 | { | 88 | { |
89 | BIO bio; | 89 | return fwrite(str, 1, len, fp); |
90 | |||
91 | BIO_set(&bio,BIO_s_file()); | ||
92 | BIO_set_fp(&bio,fp,BIO_NOCLOSE); | ||
93 | |||
94 | return BIO_printf(&bio, "%s", str); | ||
95 | } | 90 | } |
96 | void ERR_print_errors_fp(FILE *fp) | 91 | void ERR_print_errors_fp(FILE *fp) |
97 | { | 92 | { |
@@ -99,13 +94,64 @@ void ERR_print_errors_fp(FILE *fp) | |||
99 | } | 94 | } |
100 | #endif | 95 | #endif |
101 | 96 | ||
102 | static int print_bio(const char *str, size_t len, void *bp) | 97 | void ERR_error_string_n(unsigned long e, char *buf, size_t len) |
103 | { | 98 | { |
104 | return BIO_write((BIO *)bp, str, len); | 99 | char lsbuf[64], fsbuf[64], rsbuf[64]; |
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 | } | ||
105 | } | 144 | } |
106 | void ERR_print_errors(BIO *bp) | 145 | |
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) | ||
107 | { | 150 | { |
108 | ERR_print_errors_cb(print_bio, bp); | 151 | static char buf[256]; |
109 | } | 152 | |
153 | if (ret == NULL) ret=buf; | ||
154 | ERR_error_string_n(e, ret, 256); | ||
110 | 155 | ||
111 | 156 | return ret; | |
157 | } | ||