summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2019-09-04 22:04:08 +0200
committerRichard Levitte <levitte@openssl.org>2019-09-12 17:59:52 +0200
commitb13342e933c507c4ce0eda0a0193339a111f27a5 (patch)
tree27251f00624c771cd42e0f649513ef8330659a40 /crypto
parent06ff79bd773d0b4214e4b6a8a1332a3355b17742 (diff)
Modernise the ERR functionality further (new functions and deprecations)
ERR_func_error_string() essentially returns NULL, and since all function codes are now removed for all intents and purposes, this function has fallen out of use and cannot be modified to suit the data, since its only function is to interpret an error code. To compensate for the loss of error code, we instead provide new functions that extracts the function name strings from an error record: - ERR_get_error_func() - ERR_peek_error_func() - ERR_peek_last_error_func() Similarly, the once all encompasing functions ERR_peek_last_error_line_data(), ERR_peek_error_line_data() and ERR_get_error_line_data() lack the capability of getting the function name string, so we deprecate those and add these functions to replace them: - ERR_get_error_all() - ERR_peek_error_all() - ERR_peek_last_error_all() Finally, we adjust a few lines of code that used the now deprecated functions. Fixes #9756 Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9756)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/err/err.c105
1 files changed, 85 insertions, 20 deletions
diff --git a/crypto/err/err.c b/crypto/err/err.c
index 25ab13509c..deaa579090 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -126,8 +126,8 @@ static LHASH_OF(ERR_STRING_DATA) *int_error_hash = NULL;
static int int_err_library_number = ERR_LIB_USER;
static unsigned long get_error_values(int inc, int top, const char **file,
- int *line, const char **data,
- int *flags);
+ int *line, const char **func,
+ const char **data, int *flags);
static unsigned long err_string_data_hash(const ERR_STRING_DATA *a)
{
@@ -371,55 +371,112 @@ void ERR_clear_error(void)
unsigned long ERR_get_error(void)
{
- return get_error_values(1, 0, NULL, NULL, NULL, NULL);
+ return get_error_values(1, 0, NULL, NULL, NULL, NULL, NULL);
}
unsigned long ERR_get_error_line(const char **file, int *line)
{
- return get_error_values(1, 0, file, line, NULL, NULL);
+ return get_error_values(1, 0, file, line, NULL, NULL, NULL);
}
+unsigned long ERR_get_error_func(const char **func)
+{
+ return get_error_values(1, 0, NULL, NULL, func, NULL, NULL);
+}
+
+unsigned long ERR_get_error_data(const char **data, int *flags)
+{
+ return get_error_values(1, 0, NULL, NULL, NULL, data, flags);
+}
+
+unsigned long ERR_get_error_all(const char **file, int *line,
+ const char **func,
+ const char **data, int *flags)
+{
+ return get_error_values(1, 0, file, line, func, data, flags);
+}
+
+#if !OPENSSL_API_3
unsigned long ERR_get_error_line_data(const char **file, int *line,
const char **data, int *flags)
{
- return get_error_values(1, 0, file, line, data, flags);
+ return get_error_values(1, 0, file, line, NULL, data, flags);
}
+#endif
unsigned long ERR_peek_error(void)
{
- return get_error_values(0, 0, NULL, NULL, NULL, NULL);
+ return get_error_values(0, 0, NULL, NULL, NULL, NULL, NULL);
}
unsigned long ERR_peek_error_line(const char **file, int *line)
{
- return get_error_values(0, 0, file, line, NULL, NULL);
+ return get_error_values(0, 0, file, line, NULL, NULL, NULL);
+}
+
+unsigned long ERR_peek_error_func(const char **func)
+{
+ return get_error_values(0, 0, NULL, NULL, func, NULL, NULL);
+}
+
+unsigned long ERR_peek_error_data(const char **data, int *flags)
+{
+ return get_error_values(0, 0, NULL, NULL, NULL, data, flags);
+}
+
+unsigned long ERR_peek_error_all(const char **file, int *line,
+ const char **func,
+ const char **data, int *flags)
+{
+ return get_error_values(0, 0, file, line, func, data, flags);
}
+#if !OPENSSL_API_3
unsigned long ERR_peek_error_line_data(const char **file, int *line,
const char **data, int *flags)
{
- return get_error_values(0, 0, file, line, data, flags);
+ return get_error_values(0, 0, file, line, NULL, data, flags);
}
+#endif
unsigned long ERR_peek_last_error(void)
{
- return get_error_values(0, 1, NULL, NULL, NULL, NULL);
+ return get_error_values(0, 1, NULL, NULL, NULL, NULL, NULL);
}
unsigned long ERR_peek_last_error_line(const char **file, int *line)
{
- return get_error_values(0, 1, file, line, NULL, NULL);
+ return get_error_values(0, 1, file, line, NULL, NULL, NULL);
+}
+
+unsigned long ERR_peek_last_error_func(const char **func)
+{
+ return get_error_values(0, 1, NULL, NULL, func, NULL, NULL);
+}
+
+unsigned long ERR_peek_last_error_data(const char **data, int *flags)
+{
+ return get_error_values(0, 1, NULL, NULL, NULL, data, flags);
+}
+
+unsigned long ERR_peek_last_error_all(const char **file, int *line,
+ const char **func,
+ const char **data, int *flags)
+{
+ return get_error_values(0, 1, file, line, func, data, flags);
}
+#if !OPENSSL_API_3
unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
const char **data, int *flags)
{
- return get_error_values(0, 1, file, line, data, flags);
+ return get_error_values(0, 1, file, line, NULL, data, flags);
}
+#endif
static unsigned long get_error_values(int inc, int top, const char **file,
- int *line, const char **data,
- int *flags)
+ int *line, const char **func,
+ const char **data, int *flags)
{
int i = 0;
ERR_STATE *es;
@@ -430,13 +487,15 @@ static unsigned long get_error_values(int inc, int top, const char **file,
return 0;
if (inc && top) {
- if (file)
+ if (file != NULL)
*file = "";
- if (line)
+ if (line != NULL)
*line = 0;
- if (data)
+ if (func != NULL)
+ *func = "";
+ if (data != NULL)
*data = "";
- if (flags)
+ if (flags != NULL)
*flags = 0;
return ERR_R_INTERNAL_ERROR;
@@ -481,6 +540,12 @@ static unsigned long get_error_values(int inc, int top, const char **file,
}
}
+ if (func != NULL) {
+ *func = es->err_func[i];
+ if (*func == NULL)
+ *func = "N/A";
+ }
+
if (data == NULL) {
if (inc) {
err_clear_data(es, i, 0);
@@ -558,12 +623,12 @@ const char *ERR_lib_error_string(unsigned long e)
return ((p == NULL) ? NULL : p->string);
}
+#if !OPENSSL_API_3
const char *ERR_func_error_string(unsigned long e)
{
- if (!RUN_ONCE(&err_string_init, do_err_strings_init))
- return NULL;
- return ERR_GET_LIB(e) == ERR_LIB_SYS ? "system library" : NULL;
+ return NULL;
}
+#endif
const char *ERR_reason_error_string(unsigned long e)
{