diff options
Diffstat (limited to 'src/lib/libcrypto/err/err.c')
-rw-r--r-- | src/lib/libcrypto/err/err.c | 106 |
1 files changed, 105 insertions, 1 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index 93c64cbc4f..eb8c76aa0b 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c | |||
@@ -55,9 +55,63 @@ | |||
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
58 | 111 | ||
59 | #include <stdio.h> | 112 | #include <stdio.h> |
60 | #include <stdarg.h> | 113 | #include <stdarg.h> |
114 | #include <string.h> | ||
61 | #include <openssl/lhash.h> | 115 | #include <openssl/lhash.h> |
62 | #include <openssl/crypto.h> | 116 | #include <openssl/crypto.h> |
63 | #include "cryptlib.h" | 117 | #include "cryptlib.h" |
@@ -154,6 +208,54 @@ static ERR_STRING_DATA ERR_str_reasons[]= | |||
154 | 208 | ||
155 | {0,NULL}, | 209 | {0,NULL}, |
156 | }; | 210 | }; |
211 | |||
212 | |||
213 | #define NUM_SYS_STR_REASONS 127 | ||
214 | #define LEN_SYS_STR_REASON 32 | ||
215 | |||
216 | static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1]; | ||
217 | /* SYS_str_reasons is filled with copies of strerror() results at | ||
218 | * initialization. | ||
219 | * 'errno' values up to 127 should cover all usual errors, | ||
220 | * others will be displayed numerically by ERR_error_string. | ||
221 | * It is crucial that we have something for each reason code | ||
222 | * that occurs in ERR_str_reasons, or bogus reason strings | ||
223 | * will be returned for SYSerr(), which always gets an errno | ||
224 | * value and never one of those 'standard' reason codes. */ | ||
225 | |||
226 | static void build_SYS_str_reasons() | ||
227 | { | ||
228 | /* Malloc cannot be used here, use static storage instead */ | ||
229 | static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; | ||
230 | int i; | ||
231 | |||
232 | CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH); | ||
233 | |||
234 | for (i = 1; i <= NUM_SYS_STR_REASONS; i++) | ||
235 | { | ||
236 | ERR_STRING_DATA *str = &SYS_str_reasons[i - 1]; | ||
237 | |||
238 | str->error = (unsigned long)i; | ||
239 | if (str->string == NULL) | ||
240 | { | ||
241 | char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]); | ||
242 | char *src = strerror(i); | ||
243 | if (src != NULL) | ||
244 | { | ||
245 | strncpy(*dest, src, sizeof *dest); | ||
246 | (*dest)[sizeof *dest - 1] = '\0'; | ||
247 | str->string = *dest; | ||
248 | } | ||
249 | } | ||
250 | if (str->string == NULL) | ||
251 | str->string = "unknown"; | ||
252 | } | ||
253 | |||
254 | /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL}, | ||
255 | * as required by ERR_load_strings. */ | ||
256 | |||
257 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH); | ||
258 | } | ||
157 | #endif | 259 | #endif |
158 | 260 | ||
159 | #define err_clear_data(p,i) \ | 261 | #define err_clear_data(p,i) \ |
@@ -191,14 +293,16 @@ void ERR_load_ERR_strings(void) | |||
191 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | 293 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); |
192 | return; | 294 | return; |
193 | } | 295 | } |
194 | init=0; | ||
195 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); | 296 | CRYPTO_w_unlock(CRYPTO_LOCK_ERR); |
196 | 297 | ||
197 | #ifndef NO_ERR | 298 | #ifndef NO_ERR |
198 | ERR_load_strings(0,ERR_str_libraries); | 299 | ERR_load_strings(0,ERR_str_libraries); |
199 | ERR_load_strings(0,ERR_str_reasons); | 300 | ERR_load_strings(0,ERR_str_reasons); |
200 | ERR_load_strings(ERR_LIB_SYS,ERR_str_functs); | 301 | ERR_load_strings(ERR_LIB_SYS,ERR_str_functs); |
302 | build_SYS_str_reasons(); | ||
303 | ERR_load_strings(ERR_LIB_SYS,SYS_str_reasons); | ||
201 | #endif | 304 | #endif |
305 | init=0; | ||
202 | } | 306 | } |
203 | } | 307 | } |
204 | 308 | ||