summaryrefslogtreecommitdiffstats
path: root/src/crypto/err/err.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/crypto/err/err.c')
-rw-r--r--src/crypto/err/err.c132
1 files changed, 76 insertions, 56 deletions
diff --git a/src/crypto/err/err.c b/src/crypto/err/err.c
index 24824e8..de1b4a7 100644
--- a/src/crypto/err/err.c
+++ b/src/crypto/err/err.c
@@ -125,6 +125,10 @@
#include "../internal.h"
+extern const uint32_t kOpenSSLFunctionValues[];
+extern const size_t kOpenSSLFunctionValuesLen;
+extern const char kOpenSSLFunctionStringData[];
+
extern const uint32_t kOpenSSLReasonValues[];
extern const size_t kOpenSSLReasonValuesLen;
extern const char kOpenSSLReasonStringData[];
@@ -255,51 +259,42 @@ static uint32_t get_error_values(int inc, int top, const char **file, int *line,
}
uint32_t ERR_get_error(void) {
- return get_error_values(1 /* inc */, 0 /* bottom */, NULL, NULL, NULL, NULL);
+ return get_error_values(1, 0, NULL, NULL, NULL, NULL);
}
uint32_t ERR_get_error_line(const char **file, int *line) {
- return get_error_values(1 /* inc */, 0 /* bottom */, file, line, NULL, NULL);
+ return get_error_values(1, 0, file, line, NULL, NULL);
}
uint32_t ERR_get_error_line_data(const char **file, int *line,
const char **data, int *flags) {
- return get_error_values(1 /* inc */, 0 /* bottom */, file, line, data, flags);
+ return get_error_values(1, 0, file, line, data, flags);
}
uint32_t ERR_peek_error(void) {
- return get_error_values(0 /* peek */, 0 /* bottom */, NULL, NULL, NULL, NULL);
+ return get_error_values(0, 0, NULL, NULL, NULL, NULL);
}
uint32_t ERR_peek_error_line(const char **file, int *line) {
- return get_error_values(0 /* peek */, 0 /* bottom */, file, line, NULL, NULL);
+ return get_error_values(0, 0, file, line, NULL, NULL);
}
uint32_t ERR_peek_error_line_data(const char **file, int *line,
const char **data, int *flags) {
- return get_error_values(0 /* peek */, 0 /* bottom */, file, line, data,
- flags);
-}
-
-const char *ERR_peek_function(void) {
- ERR_STATE *state = err_get_state();
- if (state == NULL || state->bottom == state->top) {
- return NULL;
- }
- return state->errors[(state->bottom + 1) % ERR_NUM_ERRORS].function;
+ return get_error_values(0, 0, file, line, data, flags);
}
uint32_t ERR_peek_last_error(void) {
- return get_error_values(0 /* peek */, 1 /* top */, NULL, NULL, NULL, NULL);
+ return get_error_values(0, 1, NULL, NULL, NULL, NULL);
}
uint32_t ERR_peek_last_error_line(const char **file, int *line) {
- return get_error_values(0 /* peek */, 1 /* top */, file, line, NULL, NULL);
+ return get_error_values(0, 1, file, line, NULL, NULL);
}
uint32_t ERR_peek_last_error_line_data(const char **file, int *line,
const char **data, int *flags) {
- return get_error_values(0 /* peek */, 1 /* top */, file, line, data, flags);
+ return get_error_values(0, 1, file, line, data, flags);
}
void ERR_clear_error(void) {
@@ -346,20 +341,40 @@ void ERR_clear_system_error(void) {
errno = 0;
}
-static void err_error_string(uint32_t packed_error, const char *func_str,
- char *buf, size_t len) {
- char lib_buf[64], reason_buf[64];
- const char *lib_str, *reason_str;
- unsigned lib, reason;
+char *ERR_error_string(uint32_t packed_error, char *ret) {
+ static char buf[ERR_ERROR_STRING_BUF_LEN];
+
+ if (ret == NULL) {
+ /* TODO(fork): remove this. */
+ ret = buf;
+ }
+
+#if !defined(NDEBUG)
+ /* This is aimed to help catch callers who don't provide
+ * |ERR_ERROR_STRING_BUF_LEN| bytes of space. */
+ memset(ret, 0, ERR_ERROR_STRING_BUF_LEN);
+#endif
+
+ ERR_error_string_n(packed_error, ret, ERR_ERROR_STRING_BUF_LEN);
+
+ return ret;
+}
+
+void ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
+ char lib_buf[64], func_buf[64], reason_buf[64];
+ const char *lib_str, *func_str, *reason_str;
+ unsigned lib, func, reason;
if (len == 0) {
return;
}
lib = ERR_GET_LIB(packed_error);
+ func = ERR_GET_FUNC(packed_error);
reason = ERR_GET_REASON(packed_error);
lib_str = ERR_lib_error_string(packed_error);
+ func_str = ERR_func_error_string(packed_error);
reason_str = ERR_reason_error_string(packed_error);
if (lib_str == NULL) {
@@ -368,7 +383,8 @@ static void err_error_string(uint32_t packed_error, const char *func_str,
}
if (func_str == NULL) {
- func_str = "OPENSSL_internal";
+ BIO_snprintf(func_buf, sizeof(func_buf), "func(%u)", func);
+ func_str = func_buf;
}
if (reason_str == NULL) {
@@ -410,29 +426,6 @@ static void err_error_string(uint32_t packed_error, const char *func_str,
}
}
-char *ERR_error_string(uint32_t packed_error, char *ret) {
- static char buf[ERR_ERROR_STRING_BUF_LEN];
-
- if (ret == NULL) {
- /* TODO(fork): remove this. */
- ret = buf;
- }
-
-#if !defined(NDEBUG)
- /* This is aimed to help catch callers who don't provide
- * |ERR_ERROR_STRING_BUF_LEN| bytes of space. */
- memset(ret, 0, ERR_ERROR_STRING_BUF_LEN);
-#endif
-
- ERR_error_string_n(packed_error, ret, ERR_ERROR_STRING_BUF_LEN);
-
- return ret;
-}
-
-void ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
- err_error_string(packed_error, NULL, buf, len);
-}
-
// err_string_cmp is a compare function for searching error values with
// |bsearch| in |err_string_lookup|.
static int err_string_cmp(const void *a, const void *b) {
@@ -512,8 +505,8 @@ static const char *const kLibraryNames[ERR_NUM_LIBS] = {
"HMAC routines", /* ERR_LIB_HMAC */
"Digest functions", /* ERR_LIB_DIGEST */
"Cipher functions", /* ERR_LIB_CIPHER */
- "HKDF functions", /* ERR_LIB_HKDF */
"User defined functions", /* ERR_LIB_USER */
+ "HKDF functions", /* ERR_LIB_HKDF */
};
const char *ERR_lib_error_string(uint32_t packed_error) {
@@ -526,7 +519,36 @@ const char *ERR_lib_error_string(uint32_t packed_error) {
}
const char *ERR_func_error_string(uint32_t packed_error) {
- return "OPENSSL_internal";
+ const uint32_t lib = ERR_GET_LIB(packed_error);
+ const uint32_t func = ERR_GET_FUNC(packed_error);
+
+ if (lib == ERR_LIB_SYS) {
+ switch (func) {
+ case SYS_F_fopen:
+ return "fopen";
+ case SYS_F_fclose:
+ return "fclose";
+ case SYS_F_fread:
+ return "fread";
+ case SYS_F_fwrite:
+ return "fwrite";
+ case SYS_F_socket:
+ return "socket";
+ case SYS_F_setsockopt:
+ return "setsockopt";
+ case SYS_F_connect:
+ return "connect";
+ case SYS_F_getaddrinfo:
+ return "getaddrinfo";
+ default:
+ return NULL;
+ }
+ }
+
+ return err_string_lookup(ERR_GET_LIB(packed_error),
+ ERR_GET_FUNC(packed_error), kOpenSSLFunctionValues,
+ kOpenSSLFunctionValuesLen,
+ kOpenSSLFunctionStringData);
}
const char *ERR_reason_error_string(uint32_t packed_error) {
@@ -577,13 +599,12 @@ void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
const unsigned long thread_hash = (uintptr_t) err_get_state();
for (;;) {
- const char *function = ERR_peek_function();
packed_error = ERR_get_error_line_data(&file, &line, &data, &flags);
if (packed_error == 0) {
break;
}
- err_error_string(packed_error, function, buf, sizeof(buf));
+ ERR_error_string_n(packed_error, buf, sizeof(buf));
BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf,
file, line, (flags & ERR_FLAG_STRING) ? data : "");
if (callback(buf2, strlen(buf2), ctx) <= 0) {
@@ -623,8 +644,8 @@ static void err_set_error_data(char *data, int flags) {
error->flags = flags;
}
-void ERR_put_error(int library, int reason, const char *function,
- const char *file, unsigned line) {
+void ERR_put_error(int library, int func, int reason, const char *file,
+ unsigned line) {
ERR_STATE *const state = err_get_state();
struct err_error_st *error;
@@ -633,7 +654,7 @@ void ERR_put_error(int library, int reason, const char *function,
}
if (library == ERR_LIB_SYS && reason == 0) {
-#if defined(OPENSSL_WINDOWS)
+#if defined(WIN32)
reason = GetLastError();
#else
reason = errno;
@@ -647,10 +668,9 @@ void ERR_put_error(int library, int reason, const char *function,
error = &state->errors[state->top];
err_clear(error);
- error->function = function;
error->file = file;
error->line = line;
- error->packed = ERR_PACK(library, reason);
+ error->packed = ERR_PACK(library, func, reason);
}
/* ERR_add_error_data_vdata takes a variable number of const char* pointers,