No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

743 líneas
24 KiB

  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.]
  56. */
  57. /* ====================================================================
  58. * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
  59. *
  60. * Redistribution and use in source and binary forms, with or without
  61. * modification, are permitted provided that the following conditions
  62. * are met:
  63. *
  64. * 1. Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. *
  67. * 2. Redistributions in binary form must reproduce the above copyright
  68. * notice, this list of conditions and the following disclaimer in
  69. * the documentation and/or other materials provided with the
  70. * distribution.
  71. *
  72. * 3. All advertising materials mentioning features or use of this
  73. * software must display the following acknowledgment:
  74. * "This product includes software developed by the OpenSSL Project
  75. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  76. *
  77. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  78. * endorse or promote products derived from this software without
  79. * prior written permission. For written permission, please contact
  80. * openssl-core@openssl.org.
  81. *
  82. * 5. Products derived from this software may not be called "OpenSSL"
  83. * nor may "OpenSSL" appear in their names without prior written
  84. * permission of the OpenSSL Project.
  85. *
  86. * 6. Redistributions of any form whatsoever must retain the following
  87. * acknowledgment:
  88. * "This product includes software developed by the OpenSSL Project
  89. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  90. *
  91. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  92. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  93. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  94. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  95. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  96. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  97. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  98. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  99. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  100. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  101. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  102. * OF THE POSSIBILITY OF SUCH DAMAGE.
  103. * ====================================================================
  104. *
  105. * This product includes cryptographic software written by Eric Young
  106. * (eay@cryptsoft.com). This product includes software written by Tim
  107. * Hudson (tjh@cryptsoft.com). */
  108. #include <openssl/err.h>
  109. #include <assert.h>
  110. #include <errno.h>
  111. #include <inttypes.h>
  112. #include <stdarg.h>
  113. #include <stdio.h>
  114. #include <openssl/lhash.h>
  115. #include <openssl/mem.h>
  116. #include <openssl/thread.h>
  117. /* err_fns contains a pointer to the current error implementation. */
  118. static const struct ERR_FNS_st *err_fns = NULL;
  119. extern const struct ERR_FNS_st openssl_err_default_impl;
  120. #define ERRFN(a) err_fns->a
  121. /* err_fns_check is an internal function that checks whether "err_fns" is set
  122. * and if not, sets it to the default. */
  123. static void err_fns_check(void) {
  124. /* In practice, this is not a race problem because loading the error strings
  125. * at init time will cause this pointer to be set before the process goes
  126. * multithreaded. */
  127. if (err_fns) {
  128. return;
  129. }
  130. CRYPTO_w_lock(CRYPTO_LOCK_ERR);
  131. if (!err_fns) {
  132. err_fns = &openssl_err_default_impl;
  133. }
  134. CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
  135. }
  136. /* err_clear_data frees the optional |data| member of the given error. */
  137. static void err_clear_data(struct err_error_st *error) {
  138. if (error->data != NULL && (error->flags & ERR_FLAG_MALLOCED) != 0) {
  139. OPENSSL_free(error->data);
  140. }
  141. error->data = NULL;
  142. error->flags &= ~ERR_FLAG_MALLOCED;
  143. }
  144. /* err_clear clears the given queued error. */
  145. static void err_clear(struct err_error_st *error) {
  146. err_clear_data(error);
  147. memset(error, 0, sizeof(struct err_error_st));
  148. }
  149. /* err_get_state gets the ERR_STATE object for the current thread. */
  150. static ERR_STATE *err_get_state(void) {
  151. err_fns_check();
  152. return ERRFN(get_state)();
  153. }
  154. static uint32_t get_error_values(int inc, int top, const char **file, int *line,
  155. char **data, int *flags) {
  156. unsigned i = 0;
  157. ERR_STATE *state;
  158. struct err_error_st *error;
  159. uint32_t ret;
  160. state = err_get_state();
  161. if (state->bottom == state->top) {
  162. return 0;
  163. }
  164. if (top) {
  165. /* last error */
  166. i = state->top;
  167. } else {
  168. i = (state->bottom + 1) % ERR_NUM_ERRORS;
  169. }
  170. error = &state->errors[i];
  171. ret = error->packed;
  172. if (file != NULL && line != NULL) {
  173. if (error->file == NULL) {
  174. *file = "NA";
  175. *line = 0;
  176. } else {
  177. *file = error->file;
  178. *line = error->line;
  179. }
  180. }
  181. if (data != NULL) {
  182. if (error->data == NULL) {
  183. *data = "";
  184. if (flags != NULL) {
  185. *flags = 0;
  186. }
  187. } else {
  188. *data = error->data;
  189. if (flags != NULL) {
  190. *flags = error->flags & ERR_FLAG_PUBLIC_MASK;
  191. }
  192. error->data = NULL;
  193. error->flags = 0;
  194. }
  195. }
  196. if (inc) {
  197. assert(!top);
  198. err_clear(error);
  199. state->bottom = i;
  200. }
  201. return ret;
  202. }
  203. uint32_t ERR_get_error(void) {
  204. return get_error_values(1, 0, NULL, NULL, NULL, NULL);
  205. }
  206. uint32_t ERR_get_error_line(const char **file, int *line) {
  207. return get_error_values(1, 0, file, line, NULL, NULL);
  208. }
  209. uint32_t ERR_get_error_line_data(const char **file, int *line,
  210. char **data, int *flags) {
  211. return get_error_values(1, 0, file, line, data, flags);
  212. }
  213. uint32_t ERR_peek_error(void) {
  214. return get_error_values(0, 0, NULL, NULL, NULL, NULL);
  215. }
  216. uint32_t ERR_peek_error_line(const char **file, int *line) {
  217. return get_error_values(0, 0, file, line, NULL, NULL);
  218. }
  219. uint32_t ERR_peek_error_line_data(const char **file, int *line,
  220. const char **data, int *flags) {
  221. return get_error_values(0, 0, file, line, (char **) data, flags);
  222. }
  223. uint32_t ERR_peek_last_error(void) {
  224. return get_error_values(0, 1, NULL, NULL, NULL, NULL);
  225. }
  226. uint32_t ERR_peek_last_error_line(const char **file, int *line) {
  227. return get_error_values(0, 1, file, line, NULL, NULL);
  228. }
  229. uint32_t ERR_peek_last_error_line_data(const char **file, int *line,
  230. const char **data, int *flags) {
  231. return get_error_values(0, 1, file, line, (char **) data, flags);
  232. }
  233. void ERR_clear_error(void) {
  234. ERR_STATE *const state = err_get_state();
  235. unsigned i;
  236. for (i = 0; i < ERR_NUM_ERRORS; i++) {
  237. err_clear(&state->errors[i]);
  238. }
  239. state->top = state->bottom = 0;
  240. }
  241. int ERR_get_next_error_library() {
  242. err_fns_check();
  243. return ERRFN(get_next_library)();
  244. }
  245. void ERR_clear_system_error(void) {
  246. errno = 0;
  247. }
  248. char *ERR_error_string(uint32_t packed_error, char *ret) {
  249. static char buf[ERR_ERROR_STRING_BUF_LEN];
  250. if (ret == NULL) {
  251. /* TODO(fork): remove this. */
  252. ret = buf;
  253. }
  254. #if !defined(NDEBUG)
  255. /* This is aimed to help catch callers who don't provide
  256. * |ERR_ERROR_STRING_BUF_LEN| bytes of space. */
  257. memset(ret, 0, ERR_ERROR_STRING_BUF_LEN);
  258. #endif
  259. ERR_error_string_n(packed_error, ret, ERR_ERROR_STRING_BUF_LEN);
  260. return ret;
  261. }
  262. void ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
  263. char lib_buf[64], func_buf[64], reason_buf[64];
  264. const char *lib_str, *func_str, *reason_str;
  265. unsigned lib, func, reason;
  266. if (len == 0) {
  267. return;
  268. }
  269. lib = ERR_GET_LIB(packed_error);
  270. func = ERR_GET_FUNC(packed_error);
  271. reason = ERR_GET_REASON(packed_error);
  272. lib_str = ERR_lib_error_string(packed_error);
  273. func_str = ERR_func_error_string(packed_error);
  274. reason_str = ERR_reason_error_string(packed_error);
  275. if (lib_str == NULL) {
  276. BIO_snprintf(lib_buf, sizeof(lib_buf), "lib(%u)", lib);
  277. lib_str = lib_buf;
  278. }
  279. if (func_str == NULL) {
  280. BIO_snprintf(func_buf, sizeof(func_buf), "func(%u)", func);
  281. func_str = func_buf;
  282. }
  283. if (reason_str == NULL) {
  284. BIO_snprintf(reason_buf, sizeof(reason_buf), "reason(%u)", reason);
  285. reason_str = reason_buf;
  286. }
  287. BIO_snprintf(buf, len, "error:%08" PRIx32 ":%s:%s:%s",
  288. packed_error, lib_str, func_str, reason_str);
  289. if (strlen(buf) == len - 1) {
  290. /* output may be truncated; make sure we always have 5 colon-separated
  291. * fields, i.e. 4 colons. */
  292. static const unsigned num_colons = 4;
  293. unsigned i;
  294. char *s = buf;
  295. if (len <= num_colons) {
  296. /* In this situation it's not possible to ensure that the correct number
  297. * of colons are included in the output. */
  298. return;
  299. }
  300. for (i = 0; i < num_colons; i++) {
  301. char *colon = strchr(s, ':');
  302. char *last_pos = &buf[len - 1] - num_colons + i;
  303. if (colon == NULL || colon > last_pos) {
  304. /* set colon |i| at last possible position (buf[len-1] is the
  305. * terminating 0). If we're setting this colon, then all whole of the
  306. * rest of the string must be colons in order to have the correct
  307. * number. */
  308. memset(last_pos, ':', num_colons - i);
  309. break;
  310. }
  311. s = colon + 1;
  312. }
  313. }
  314. }
  315. /* err_component_error_string returns the error string associated with
  316. * |packed_error|, which must be of a special form matching the keys inserted
  317. * into the error hash table. */
  318. static const char *err_component_error_string(uint32_t packed_error) {
  319. ERR_STRING_DATA *p;
  320. err_fns_check();
  321. p = ERRFN(get_item)(packed_error);
  322. if (p == NULL) {
  323. return NULL;
  324. }
  325. return p->string;
  326. }
  327. const char *ERR_lib_error_string(uint32_t packed_error) {
  328. return err_component_error_string(ERR_PACK(ERR_GET_LIB(packed_error), 0, 0));
  329. }
  330. const char *ERR_func_error_string(uint32_t packed_error) {
  331. return err_component_error_string(
  332. ERR_PACK(ERR_GET_LIB(packed_error), ERR_GET_FUNC(packed_error), 0));
  333. }
  334. const char *ERR_reason_error_string(uint32_t packed_error) {
  335. const char *reason_str = err_component_error_string(
  336. ERR_PACK(ERR_GET_LIB(packed_error), 0, ERR_GET_REASON(packed_error)));
  337. if (reason_str != NULL) {
  338. return reason_str;
  339. }
  340. return err_component_error_string(
  341. ERR_PACK(0, 0, ERR_GET_REASON(packed_error)));
  342. }
  343. void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
  344. CRYPTO_THREADID current_thread;
  345. char buf[ERR_ERROR_STRING_BUF_LEN];
  346. char buf2[1024];
  347. unsigned long thread_hash;
  348. const char *file;
  349. char *data;
  350. int line, flags;
  351. uint32_t packed_error;
  352. CRYPTO_THREADID_current(&current_thread);
  353. thread_hash = CRYPTO_THREADID_hash(&current_thread);
  354. for (;;) {
  355. packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
  356. if (packed_error == 0) {
  357. break;
  358. }
  359. ERR_error_string_n(packed_error, buf, sizeof(buf));
  360. BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf,
  361. file, line, (flags & ERR_FLAG_STRING) ? data : "");
  362. if (callback(buf2, strlen(buf2), ctx) <= 0) {
  363. break;
  364. }
  365. if (flags & ERR_FLAG_MALLOCED) {
  366. OPENSSL_free(data);
  367. }
  368. }
  369. }
  370. /* err_set_error_data sets the data on the most recent error. The |flags|
  371. * argument is a combination of the |ERR_FLAG_*| values. */
  372. static void err_set_error_data(char *data, int flags) {
  373. ERR_STATE *const state = err_get_state();
  374. struct err_error_st *error;
  375. if (state->top == state->bottom) {
  376. return;
  377. }
  378. error = &state->errors[state->top];
  379. err_clear_data(error);
  380. error->data = data;
  381. error->flags = flags;
  382. }
  383. void ERR_put_error(int library, int func, int reason, const char *file,
  384. unsigned line) {
  385. ERR_STATE *const state = err_get_state();
  386. struct err_error_st *error;
  387. if (library == ERR_LIB_SYS && reason == 0) {
  388. #if defined(WIN32)
  389. reason = GetLastError();
  390. #else
  391. reason = errno;
  392. #endif
  393. }
  394. state->top = (state->top + 1) % ERR_NUM_ERRORS;
  395. if (state->top == state->bottom) {
  396. state->bottom = (state->bottom + 1) % ERR_NUM_ERRORS;
  397. }
  398. error = &state->errors[state->top];
  399. err_clear(error);
  400. error->file = file;
  401. error->line = line;
  402. error->packed = ERR_PACK(library, func, reason);
  403. }
  404. /* ERR_add_error_data_vdata takes a variable number of const char* pointers,
  405. * concatenates them and sets the result as the data on the most recent
  406. * error. */
  407. static void err_add_error_vdata(unsigned num, va_list args) {
  408. size_t alloced, new_len, len = 0, substr_len;
  409. char *buf;
  410. const char *substr;
  411. unsigned i;
  412. alloced = 80;
  413. buf = OPENSSL_malloc(alloced + 1);
  414. if (buf == NULL) {
  415. return;
  416. }
  417. for (i = 0; i < num; i++) {
  418. substr = va_arg(args, const char *);
  419. if (substr == NULL) {
  420. continue;
  421. }
  422. substr_len = strlen(substr);
  423. new_len = len + substr_len;
  424. if (new_len > alloced) {
  425. char *new_buf;
  426. if (alloced + 20 + 1 < alloced) {
  427. /* overflow. */
  428. OPENSSL_free(buf);
  429. return;
  430. }
  431. alloced = new_len + 20;
  432. new_buf = OPENSSL_realloc(buf, alloced + 1);
  433. if (new_buf == NULL) {
  434. OPENSSL_free(buf);
  435. return;
  436. }
  437. buf = new_buf;
  438. }
  439. memcpy(buf + len, substr, substr_len);
  440. len = new_len;
  441. }
  442. buf[len] = 0;
  443. err_set_error_data(buf, ERR_FLAG_MALLOCED | ERR_FLAG_STRING);
  444. }
  445. void ERR_add_error_data(unsigned count, ...) {
  446. va_list args;
  447. va_start(args, count);
  448. err_add_error_vdata(count, args);
  449. va_end(args);
  450. }
  451. void ERR_add_error_dataf(const char *format, ...) {
  452. va_list ap;
  453. char *buf;
  454. static const unsigned buf_len = 256;
  455. /* A fixed-size buffer is used because va_copy (which would be needed in
  456. * order to call vsnprintf twice and measure the buffer) wasn't defined until
  457. * C99. */
  458. buf = OPENSSL_malloc(buf_len + 1);
  459. if (buf == NULL) {
  460. return;
  461. }
  462. va_start(ap, format);
  463. BIO_vsnprintf(buf, buf_len, format, ap);
  464. buf[buf_len] = 0;
  465. va_end(ap);
  466. err_set_error_data(buf, ERR_FLAG_MALLOCED | ERR_FLAG_STRING);
  467. }
  468. int ERR_set_mark(void) {
  469. ERR_STATE *const state = err_get_state();
  470. if (state->bottom == state->top) {
  471. return 0;
  472. }
  473. state->errors[state->top].flags |= ERR_FLAG_MARK;
  474. return 1;
  475. }
  476. int ERR_pop_to_mark(void) {
  477. ERR_STATE *const state = err_get_state();
  478. struct err_error_st *error;
  479. while (state->bottom != state->top) {
  480. error = &state->errors[state->top];
  481. if ((error->flags & ERR_FLAG_MARK) != 0) {
  482. break;
  483. }
  484. err_clear(error);
  485. if (state->top == 0) {
  486. state->top = ERR_NUM_ERRORS - 1;
  487. } else {
  488. state->top--;
  489. }
  490. }
  491. if (state->bottom == state->top) {
  492. return 0;
  493. }
  494. error->flags &= ~ERR_FLAG_MARK;
  495. return 1;
  496. }
  497. static const char *const kLibraryNames[ERR_NUM_LIBS] = {
  498. "invalid library (0)",
  499. "unknown library", /* ERR_LIB_NONE */
  500. "system library", /* ERR_LIB_SYS */
  501. "bignum routines", /* ERR_LIB_BN */
  502. "RSA routines", /* ERR_LIB_RSA */
  503. "Diffie-Hellman routines", /* ERR_LIB_DH */
  504. "public key routines", /* ERR_LIB_EVP */
  505. "memory buffer routines", /* ERR_LIB_BUF */
  506. "object identifier routines", /* ERR_LIB_OBJ */
  507. "PEM routines", /* ERR_LIB_PEM */
  508. "DSA routines", /* ERR_LIB_DSA */
  509. "X.509 certificate routines", /* ERR_LIB_X509 */
  510. "ASN.1 encoding routines", /* ERR_LIB_ASN1 */
  511. "configuration file routines", /* ERR_LIB_CONF */
  512. "common libcrypto routines", /* ERR_LIB_CRYPTO */
  513. "elliptic curve routines", /* ERR_LIB_EC */
  514. "SSL routines", /* ERR_LIB_SSL */
  515. "BIO routines", /* ERR_LIB_BIO */
  516. "PKCS7 routines", /* ERR_LIB_PKCS7 */
  517. "PKCS8 routines", /* ERR_LIB_PKCS8 */
  518. "X509 V3 routines", /* ERR_LIB_X509V3 */
  519. "PKCS12 routines", /* ERR_LIB_PKCS12 */
  520. "random number generator", /* ERR_LIB_RAND */
  521. "ENGINE routines", /* ERR_LIB_ENGINE */
  522. "OCSP routines", /* ERR_LIB_OCSP */
  523. "UI routines", /* ERR_LIB_UI */
  524. "COMP routines", /* ERR_LIB_COMP */
  525. "ECDSA routines", /* ERR_LIB_ECDSA */
  526. "ECDH routines", /* ERR_LIB_ECDH */
  527. "HMAC routines", /* ERR_LIB_HMAC */
  528. "Digest functions", /* ERR_LIB_DIGEST */
  529. "Cipher functions", /* ERR_LIB_CIPHER */
  530. "User defined functions", /* ERR_LIB_USER */
  531. };
  532. #define NUM_SYS_ERRNOS 127
  533. /* kStaticErrors provides storage for ERR_STRING_DATA values that are created
  534. * at init time because we assume that ERR_STRING_DATA structures aren't
  535. * allocated on the heap. */
  536. static ERR_STRING_DATA kStaticErrors[ERR_NUM_LIBS * 2 + NUM_SYS_ERRNOS];
  537. static ERR_STRING_DATA kGlobalErrors[] = {
  538. {ERR_R_MALLOC_FAILURE, "malloc failure"},
  539. {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, "function should not be called"},
  540. {ERR_R_PASSED_NULL_PARAMETER, "passed a null parameter"},
  541. {ERR_R_INTERNAL_ERROR, "internal error"},
  542. {ERR_PACK(ERR_LIB_SYS, SYS_F_fopen, 0), "fopen"},
  543. {ERR_PACK(ERR_LIB_SYS, SYS_F_fclose, 0), "fclose"},
  544. {ERR_PACK(ERR_LIB_SYS, SYS_F_fread, 0), "fread"},
  545. {ERR_PACK(ERR_LIB_SYS, SYS_F_fwrite, 0), "fwrite"},
  546. {ERR_PACK(ERR_LIB_SYS, SYS_F_socket, 0), "socket"},
  547. {ERR_PACK(ERR_LIB_SYS, SYS_F_setsockopt, 0), "setsockopt"},
  548. {ERR_PACK(ERR_LIB_SYS, SYS_F_connect, 0), "connect"},
  549. {ERR_PACK(ERR_LIB_SYS, SYS_F_getaddrinfo, 0), "getaddrinfo"},
  550. {0, NULL},
  551. };
  552. extern const ERR_STRING_DATA ASN1_error_string_data[];
  553. extern const ERR_STRING_DATA BIO_error_string_data[];
  554. extern const ERR_STRING_DATA BN_error_string_data[];
  555. extern const ERR_STRING_DATA BUF_error_string_data[];
  556. extern const ERR_STRING_DATA CIPHER_error_string_data[];
  557. extern const ERR_STRING_DATA CONF_error_string_data[];
  558. extern const ERR_STRING_DATA CRYPTO_error_string_data[];
  559. extern const ERR_STRING_DATA DH_error_string_data[];
  560. extern const ERR_STRING_DATA DIGEST_error_string_data[];
  561. extern const ERR_STRING_DATA DSA_error_string_data[];
  562. extern const ERR_STRING_DATA ECDH_error_string_data[];
  563. extern const ERR_STRING_DATA ECDSA_error_string_data[];
  564. extern const ERR_STRING_DATA EC_error_string_data[];
  565. extern const ERR_STRING_DATA EVP_error_string_data[];
  566. extern const ERR_STRING_DATA OBJ_error_string_data[];
  567. extern const ERR_STRING_DATA PEM_error_string_data[];
  568. extern const ERR_STRING_DATA RSA_error_string_data[];
  569. extern const ERR_STRING_DATA X509V3_error_string_data[];
  570. extern const ERR_STRING_DATA X509_error_string_data[];
  571. static void err_load_strings(void) {
  572. unsigned i, j = 0;
  573. err_fns_check();
  574. /* This loop loads strings for the libraries for the ERR_R_*_LIB
  575. * reasons. */
  576. for (i = ERR_LIB_NONE; i < ERR_NUM_LIBS; i++) {
  577. ERR_STRING_DATA *data = &kStaticErrors[j++];
  578. data->string = kLibraryNames[i];
  579. data->error = ERR_PACK(i, 0, 0);
  580. ERRFN(set_item)(data);
  581. data = &kStaticErrors[j++];
  582. data->string = kLibraryNames[i];
  583. data->error = ERR_PACK(0, 0, i);
  584. ERRFN(set_item)(data);
  585. }
  586. for (i = 1; i < 1 + NUM_SYS_ERRNOS; i++) {
  587. /* The "SYS" library sets errno values as the reason for its errors.
  588. * Thus we load the first |NUM_SYS_ERRNOS| errno strings as the
  589. * reason strings for that library. */
  590. ERR_STRING_DATA *data = &kStaticErrors[j++];
  591. data->string = strerror(i);
  592. data->error = ERR_PACK(ERR_LIB_SYS, 0, i);
  593. ERRFN(set_item)(data);
  594. }
  595. ERR_load_strings(kGlobalErrors);
  596. ERR_load_strings(ASN1_error_string_data);
  597. ERR_load_strings(BIO_error_string_data);
  598. ERR_load_strings(BN_error_string_data);
  599. ERR_load_strings(BUF_error_string_data);
  600. ERR_load_strings(CIPHER_error_string_data);
  601. ERR_load_strings(CONF_error_string_data);
  602. ERR_load_strings(CRYPTO_error_string_data);
  603. ERR_load_strings(DH_error_string_data);
  604. ERR_load_strings(DIGEST_error_string_data);
  605. ERR_load_strings(DSA_error_string_data);
  606. ERR_load_strings(ECDH_error_string_data);
  607. ERR_load_strings(ECDSA_error_string_data);
  608. ERR_load_strings(EC_error_string_data);
  609. ERR_load_strings(EVP_error_string_data);
  610. ERR_load_strings(OBJ_error_string_data);
  611. ERR_load_strings(PEM_error_string_data);
  612. ERR_load_strings(RSA_error_string_data);
  613. ERR_load_strings(X509V3_error_string_data);
  614. ERR_load_strings(X509_error_string_data);
  615. }
  616. void ERR_load_strings(const ERR_STRING_DATA *str) {
  617. err_fns_check();
  618. while (str->error) {
  619. ERRFN(set_item)(str);
  620. str++;
  621. }
  622. }
  623. void ERR_load_crypto_strings() { err_load_strings(); }
  624. void ERR_free_strings() {
  625. err_fns_check();
  626. ERRFN(shutdown)();
  627. }
  628. void ERR_load_BIO_strings() {}