You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

738 lines
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. void ERR_clear_system_error(void) {
  242. errno = 0;
  243. }
  244. char *ERR_error_string(uint32_t packed_error, char *ret) {
  245. static char buf[ERR_ERROR_STRING_BUF_LEN];
  246. if (ret == NULL) {
  247. /* TODO(fork): remove this. */
  248. ret = buf;
  249. }
  250. #if !defined(NDEBUG)
  251. /* This is aimed to help catch callers who don't provide
  252. * |ERR_ERROR_STRING_BUF_LEN| bytes of space. */
  253. memset(ret, 0, ERR_ERROR_STRING_BUF_LEN);
  254. #endif
  255. ERR_error_string_n(packed_error, ret, ERR_ERROR_STRING_BUF_LEN);
  256. return ret;
  257. }
  258. void ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
  259. char lib_buf[64], func_buf[64], reason_buf[64];
  260. const char *lib_str, *func_str, *reason_str;
  261. unsigned lib, func, reason;
  262. if (len == 0) {
  263. return;
  264. }
  265. lib = ERR_GET_LIB(packed_error);
  266. func = ERR_GET_FUNC(packed_error);
  267. reason = ERR_GET_REASON(packed_error);
  268. lib_str = ERR_lib_error_string(packed_error);
  269. func_str = ERR_func_error_string(packed_error);
  270. reason_str = ERR_reason_error_string(packed_error);
  271. if (lib_str == NULL) {
  272. BIO_snprintf(lib_buf, sizeof(lib_buf), "lib(%u)", lib);
  273. lib_str = lib_buf;
  274. }
  275. if (func_str == NULL) {
  276. BIO_snprintf(func_buf, sizeof(func_buf), "func(%u)", func);
  277. func_str = func_buf;
  278. }
  279. if (reason_str == NULL) {
  280. BIO_snprintf(reason_buf, sizeof(reason_buf), "reason(%u)", reason);
  281. reason_str = reason_buf;
  282. }
  283. BIO_snprintf(buf, len, "error:%08" PRIx32 ":%s:%s:%s",
  284. packed_error, lib_str, func_str, reason_str);
  285. if (strlen(buf) == len - 1) {
  286. /* output may be truncated; make sure we always have 5 colon-separated
  287. * fields, i.e. 4 colons. */
  288. static const unsigned num_colons = 4;
  289. unsigned i;
  290. char *s = buf;
  291. if (len <= num_colons) {
  292. /* In this situation it's not possible to ensure that the correct number
  293. * of colons are included in the output. */
  294. return;
  295. }
  296. for (i = 0; i < num_colons; i++) {
  297. char *colon = strchr(s, ':');
  298. char *last_pos = &buf[len - 1] - num_colons + i;
  299. if (colon == NULL || colon > last_pos) {
  300. /* set colon |i| at last possible position (buf[len-1] is the
  301. * terminating 0). If we're setting this colon, then all whole of the
  302. * rest of the string must be colons in order to have the correct
  303. * number. */
  304. memset(last_pos, ':', num_colons - i);
  305. break;
  306. }
  307. s = colon + 1;
  308. }
  309. }
  310. }
  311. /* err_component_error_string returns the error string associated with
  312. * |packed_error|, which must be of a special form matching the keys inserted
  313. * into the error hash table. */
  314. static const char *err_component_error_string(uint32_t packed_error) {
  315. ERR_STRING_DATA *p;
  316. err_fns_check();
  317. p = ERRFN(get_item)(packed_error);
  318. if (p == NULL) {
  319. return NULL;
  320. }
  321. return p->string;
  322. }
  323. const char *ERR_lib_error_string(uint32_t packed_error) {
  324. return err_component_error_string(ERR_PACK(ERR_GET_LIB(packed_error), 0, 0));
  325. }
  326. const char *ERR_func_error_string(uint32_t packed_error) {
  327. return err_component_error_string(
  328. ERR_PACK(ERR_GET_LIB(packed_error), ERR_GET_FUNC(packed_error), 0));
  329. }
  330. const char *ERR_reason_error_string(uint32_t packed_error) {
  331. const char *reason_str = err_component_error_string(
  332. ERR_PACK(ERR_GET_LIB(packed_error), 0, ERR_GET_REASON(packed_error)));
  333. if (reason_str != NULL) {
  334. return reason_str;
  335. }
  336. return err_component_error_string(
  337. ERR_PACK(0, 0, ERR_GET_REASON(packed_error)));
  338. }
  339. void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
  340. CRYPTO_THREADID current_thread;
  341. char buf[ERR_ERROR_STRING_BUF_LEN];
  342. char buf2[1024];
  343. unsigned long thread_hash;
  344. const char *file;
  345. char *data;
  346. int line, flags;
  347. uint32_t packed_error;
  348. CRYPTO_THREADID_current(&current_thread);
  349. thread_hash = CRYPTO_THREADID_hash(&current_thread);
  350. for (;;) {
  351. packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
  352. if (packed_error == 0) {
  353. break;
  354. }
  355. ERR_error_string_n(packed_error, buf, sizeof(buf));
  356. BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf,
  357. file, line, (flags & ERR_FLAG_STRING) ? data : "");
  358. if (callback(buf2, strlen(buf2), ctx) <= 0) {
  359. break;
  360. }
  361. if (flags & ERR_FLAG_MALLOCED) {
  362. OPENSSL_free(data);
  363. }
  364. }
  365. }
  366. /* err_set_error_data sets the data on the most recent error. The |flags|
  367. * argument is a combination of the |ERR_FLAG_*| values. */
  368. static void err_set_error_data(char *data, int flags) {
  369. ERR_STATE *const state = err_get_state();
  370. struct err_error_st *error;
  371. if (state->top == state->bottom) {
  372. return;
  373. }
  374. error = &state->errors[state->top];
  375. err_clear_data(error);
  376. error->data = data;
  377. error->flags = flags;
  378. }
  379. void ERR_put_error(int library, int func, int reason, const char *file,
  380. unsigned line) {
  381. ERR_STATE *const state = err_get_state();
  382. struct err_error_st *error;
  383. if (library == ERR_LIB_SYS && reason == 0) {
  384. #if defined(WIN32)
  385. reason = GetLastError();
  386. #else
  387. reason = errno;
  388. #endif
  389. }
  390. state->top = (state->top + 1) % ERR_NUM_ERRORS;
  391. if (state->top == state->bottom) {
  392. state->bottom = (state->bottom + 1) % ERR_NUM_ERRORS;
  393. }
  394. error = &state->errors[state->top];
  395. err_clear(error);
  396. error->file = file;
  397. error->line = line;
  398. error->packed = ERR_PACK(library, func, reason);
  399. }
  400. /* ERR_add_error_data_vdata takes a variable number of const char* pointers,
  401. * concatenates them and sets the result as the data on the most recent
  402. * error. */
  403. static void err_add_error_vdata(unsigned num, va_list args) {
  404. size_t alloced, new_len, len = 0, substr_len;
  405. char *buf;
  406. const char *substr;
  407. unsigned i;
  408. alloced = 80;
  409. buf = OPENSSL_malloc(alloced + 1);
  410. if (buf == NULL) {
  411. return;
  412. }
  413. for (i = 0; i < num; i++) {
  414. substr = va_arg(args, const char *);
  415. if (substr == NULL) {
  416. continue;
  417. }
  418. substr_len = strlen(substr);
  419. new_len = len + substr_len;
  420. if (new_len > alloced) {
  421. char *new_buf;
  422. if (alloced + 20 + 1 < alloced) {
  423. /* overflow. */
  424. OPENSSL_free(buf);
  425. return;
  426. }
  427. alloced = new_len + 20;
  428. new_buf = OPENSSL_realloc(buf, alloced + 1);
  429. if (new_buf == NULL) {
  430. OPENSSL_free(buf);
  431. return;
  432. }
  433. buf = new_buf;
  434. }
  435. memcpy(buf + len, substr, substr_len);
  436. len = new_len;
  437. }
  438. buf[len] = 0;
  439. err_set_error_data(buf, ERR_FLAG_MALLOCED | ERR_FLAG_STRING);
  440. }
  441. void ERR_add_error_data(unsigned count, ...) {
  442. va_list args;
  443. va_start(args, count);
  444. err_add_error_vdata(count, args);
  445. va_end(args);
  446. }
  447. void ERR_add_error_dataf(const char *format, ...) {
  448. va_list ap;
  449. char *buf;
  450. static const unsigned buf_len = 256;
  451. /* A fixed-size buffer is used because va_copy (which would be needed in
  452. * order to call vsnprintf twice and measure the buffer) wasn't defined until
  453. * C99. */
  454. buf = OPENSSL_malloc(buf_len + 1);
  455. if (buf == NULL) {
  456. return;
  457. }
  458. va_start(ap, format);
  459. BIO_vsnprintf(buf, buf_len, format, ap);
  460. buf[buf_len] = 0;
  461. va_end(ap);
  462. err_set_error_data(buf, ERR_FLAG_MALLOCED | ERR_FLAG_STRING);
  463. }
  464. int ERR_set_mark(void) {
  465. ERR_STATE *const state = err_get_state();
  466. if (state->bottom == state->top) {
  467. return 0;
  468. }
  469. state->errors[state->top].flags |= ERR_FLAG_MARK;
  470. return 1;
  471. }
  472. int ERR_pop_to_mark(void) {
  473. ERR_STATE *const state = err_get_state();
  474. struct err_error_st *error;
  475. while (state->bottom != state->top) {
  476. error = &state->errors[state->top];
  477. if ((error->flags & ERR_FLAG_MARK) != 0) {
  478. break;
  479. }
  480. err_clear(error);
  481. if (state->top == 0) {
  482. state->top = ERR_NUM_ERRORS - 1;
  483. } else {
  484. state->top--;
  485. }
  486. }
  487. if (state->bottom == state->top) {
  488. return 0;
  489. }
  490. error->flags &= ~ERR_FLAG_MARK;
  491. return 1;
  492. }
  493. static const char *const kLibraryNames[ERR_NUM_LIBS] = {
  494. "invalid library (0)",
  495. "unknown library", /* ERR_LIB_NONE */
  496. "system library", /* ERR_LIB_SYS */
  497. "bignum routines", /* ERR_LIB_BN */
  498. "RSA routines", /* ERR_LIB_RSA */
  499. "Diffie-Hellman routines", /* ERR_LIB_DH */
  500. "public key routines", /* ERR_LIB_EVP */
  501. "memory buffer routines", /* ERR_LIB_BUF */
  502. "object identifier routines", /* ERR_LIB_OBJ */
  503. "PEM routines", /* ERR_LIB_PEM */
  504. "DSA routines", /* ERR_LIB_DSA */
  505. "X.509 certificate routines", /* ERR_LIB_X509 */
  506. "ASN.1 encoding routines", /* ERR_LIB_ASN1 */
  507. "configuration file routines", /* ERR_LIB_CONF */
  508. "common libcrypto routines", /* ERR_LIB_CRYPTO */
  509. "elliptic curve routines", /* ERR_LIB_EC */
  510. "SSL routines", /* ERR_LIB_SSL */
  511. "BIO routines", /* ERR_LIB_BIO */
  512. "PKCS7 routines", /* ERR_LIB_PKCS7 */
  513. "PKCS8 routines", /* ERR_LIB_PKCS8 */
  514. "X509 V3 routines", /* ERR_LIB_X509V3 */
  515. "PKCS12 routines", /* ERR_LIB_PKCS12 */
  516. "random number generator", /* ERR_LIB_RAND */
  517. "ENGINE routines", /* ERR_LIB_ENGINE */
  518. "OCSP routines", /* ERR_LIB_OCSP */
  519. "UI routines", /* ERR_LIB_UI */
  520. "COMP routines", /* ERR_LIB_COMP */
  521. "ECDSA routines", /* ERR_LIB_ECDSA */
  522. "ECDH routines", /* ERR_LIB_ECDH */
  523. "HMAC routines", /* ERR_LIB_HMAC */
  524. "Digest functions", /* ERR_LIB_DIGEST */
  525. "Cipher functions", /* ERR_LIB_CIPHER */
  526. "User defined functions", /* ERR_LIB_USER */
  527. };
  528. #define NUM_SYS_ERRNOS 127
  529. /* kStaticErrors provides storage for ERR_STRING_DATA values that are created
  530. * at init time because we assume that ERR_STRING_DATA structures aren't
  531. * allocated on the heap. */
  532. static ERR_STRING_DATA kStaticErrors[ERR_NUM_LIBS * 2 + NUM_SYS_ERRNOS];
  533. static ERR_STRING_DATA kGlobalErrors[] = {
  534. {ERR_R_MALLOC_FAILURE, "malloc failure"},
  535. {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, "function should not be called"},
  536. {ERR_R_PASSED_NULL_PARAMETER, "passed a null parameter"},
  537. {ERR_R_INTERNAL_ERROR, "internal error"},
  538. {ERR_PACK(ERR_LIB_SYS, SYS_F_fopen, 0), "fopen"},
  539. {ERR_PACK(ERR_LIB_SYS, SYS_F_fclose, 0), "fclose"},
  540. {ERR_PACK(ERR_LIB_SYS, SYS_F_fread, 0), "fread"},
  541. {ERR_PACK(ERR_LIB_SYS, SYS_F_fwrite, 0), "fwrite"},
  542. {ERR_PACK(ERR_LIB_SYS, SYS_F_socket, 0), "socket"},
  543. {ERR_PACK(ERR_LIB_SYS, SYS_F_setsockopt, 0), "setsockopt"},
  544. {ERR_PACK(ERR_LIB_SYS, SYS_F_connect, 0), "connect"},
  545. {ERR_PACK(ERR_LIB_SYS, SYS_F_getaddrinfo, 0), "getaddrinfo"},
  546. {0, NULL},
  547. };
  548. extern const ERR_STRING_DATA ASN1_error_string_data[];
  549. extern const ERR_STRING_DATA BIO_error_string_data[];
  550. extern const ERR_STRING_DATA BN_error_string_data[];
  551. extern const ERR_STRING_DATA BUF_error_string_data[];
  552. extern const ERR_STRING_DATA CIPHER_error_string_data[];
  553. extern const ERR_STRING_DATA CONF_error_string_data[];
  554. extern const ERR_STRING_DATA CRYPTO_error_string_data[];
  555. extern const ERR_STRING_DATA DH_error_string_data[];
  556. extern const ERR_STRING_DATA DIGEST_error_string_data[];
  557. extern const ERR_STRING_DATA DSA_error_string_data[];
  558. extern const ERR_STRING_DATA ECDH_error_string_data[];
  559. extern const ERR_STRING_DATA ECDSA_error_string_data[];
  560. extern const ERR_STRING_DATA EC_error_string_data[];
  561. extern const ERR_STRING_DATA EVP_error_string_data[];
  562. extern const ERR_STRING_DATA OBJ_error_string_data[];
  563. extern const ERR_STRING_DATA PEM_error_string_data[];
  564. extern const ERR_STRING_DATA RSA_error_string_data[];
  565. extern const ERR_STRING_DATA X509V3_error_string_data[];
  566. extern const ERR_STRING_DATA X509_error_string_data[];
  567. static void err_load_strings(void) {
  568. unsigned i, j = 0;
  569. err_fns_check();
  570. /* This loop loads strings for the libraries for the ERR_R_*_LIB
  571. * reasons. */
  572. for (i = ERR_LIB_NONE; i < ERR_NUM_LIBS; i++) {
  573. ERR_STRING_DATA *data = &kStaticErrors[j++];
  574. data->string = kLibraryNames[i];
  575. data->error = ERR_PACK(i, 0, 0);
  576. ERRFN(set_item)(data);
  577. data = &kStaticErrors[j++];
  578. data->string = kLibraryNames[i];
  579. data->error = ERR_PACK(0, 0, i);
  580. ERRFN(set_item)(data);
  581. }
  582. for (i = 1; i < 1 + NUM_SYS_ERRNOS; i++) {
  583. /* The "SYS" library sets errno values as the reason for its errors.
  584. * Thus we load the first |NUM_SYS_ERRNOS| errno strings as the
  585. * reason strings for that library. */
  586. ERR_STRING_DATA *data = &kStaticErrors[j++];
  587. data->string = strerror(i);
  588. data->error = ERR_PACK(ERR_LIB_SYS, 0, i);
  589. ERRFN(set_item)(data);
  590. }
  591. ERR_load_strings(kGlobalErrors);
  592. ERR_load_strings(ASN1_error_string_data);
  593. ERR_load_strings(BIO_error_string_data);
  594. ERR_load_strings(BN_error_string_data);
  595. ERR_load_strings(BUF_error_string_data);
  596. ERR_load_strings(CIPHER_error_string_data);
  597. ERR_load_strings(CONF_error_string_data);
  598. ERR_load_strings(CRYPTO_error_string_data);
  599. ERR_load_strings(DH_error_string_data);
  600. ERR_load_strings(DIGEST_error_string_data);
  601. ERR_load_strings(DSA_error_string_data);
  602. ERR_load_strings(ECDH_error_string_data);
  603. ERR_load_strings(ECDSA_error_string_data);
  604. ERR_load_strings(EC_error_string_data);
  605. ERR_load_strings(EVP_error_string_data);
  606. ERR_load_strings(OBJ_error_string_data);
  607. ERR_load_strings(PEM_error_string_data);
  608. ERR_load_strings(RSA_error_string_data);
  609. ERR_load_strings(X509V3_error_string_data);
  610. ERR_load_strings(X509_error_string_data);
  611. }
  612. void ERR_load_strings(const ERR_STRING_DATA *str) {
  613. err_fns_check();
  614. while (str->error) {
  615. ERRFN(set_item)(str);
  616. str++;
  617. }
  618. }
  619. void ERR_load_crypto_strings() { err_load_strings(); }
  620. void ERR_free_strings() {
  621. err_fns_check();
  622. ERRFN(shutdown)();
  623. }
  624. void ERR_load_BIO_strings() {}