diff options
author | Richard Levitte <levitte@openssl.org> | 2019-09-04 22:14:21 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-09-12 17:59:52 +0200 |
commit | b579014d574375b57ef1f52d3e40988ebdba911c (patch) | |
tree | c1563e3fb10a8ac4468bf3b4b0849a3b84c7a06f /crypto/err | |
parent | b13342e933c507c4ce0eda0a0193339a111f27a5 (diff) |
Modernise ERR_print_errors_cb()
ERR_print_errors_cb() used functionality that isn't suitable any more,
as that functionality couldn't integrate the error record function
name strings. We therefore refactor it a bit to use better adapted
methods.
Fixes #9756
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9756)
Diffstat (limited to 'crypto/err')
-rw-r--r-- | crypto/err/err_prn.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/crypto/err/err_prn.c b/crypto/err/err_prn.c index b43367f694..9ea3eb3dee 100644 --- a/crypto/err/err_prn.c +++ b/crypto/err/err_prn.c @@ -12,24 +12,30 @@ #include <openssl/crypto.h> #include <openssl/buffer.h> #include <openssl/err.h> +#include "err_locl.h" void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u), void *u) { CRYPTO_THREAD_ID tid = CRYPTO_THREAD_get_current_id(); unsigned long l; - char buf[256]; - char buf2[4096], *hex; - const char *file, *data; + char buf[4096], *hex; + const char *lib, *reason; + const char *file, *data, *func; int line, flags; - while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) { - ERR_error_string_n(l, buf, sizeof(buf)); + while ((l = ERR_get_error_all(&file, &line, &func, &data, &flags)) != 0) { + lib = ERR_lib_error_string(l); + reason = ERR_reason_error_string(l); + if (func == NULL) + func = "unknown function"; + if ((flags & ERR_TXT_STRING) == 0) + data = ""; hex = OPENSSL_buf2hexstr((const unsigned char *)&tid, sizeof(tid)); - BIO_snprintf(buf2, sizeof(buf2), "%s:%s:%s:%d:%s\n", hex, buf, file, - line, (flags & ERR_TXT_STRING) ? data : ""); + BIO_snprintf(buf, sizeof(buf), "%s:error:%s:%s:%s:%s:%d:%s\n", + hex, lib, func, reason, file, line, data); OPENSSL_free(hex); - if (cb(buf2, strlen(buf2), u) <= 0) + if (cb(buf, strlen(buf), u) <= 0) break; /* abort outputting the error report */ } } |