summaryrefslogtreecommitdiffstats
path: root/crypto/err/err_prn.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2020-11-25 12:03:32 +0100
committerRichard Levitte <levitte@openssl.org>2020-11-27 12:02:56 +0100
commit63132c53f975b322011e08a4e8f7f8c76c3b535a (patch)
treeee1db6c880d28991e4b18f0b13620eedf2e14d5b /crypto/err/err_prn.c
parent66923436788d307c8e64cc392ffcd9631065eaa5 (diff)
ERR: Restore the similarity of ERR_print_error_cb() and ERR_error_string_n()
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org> (Merged from https://github.com/openssl/openssl/pull/13510)
Diffstat (limited to 'crypto/err/err_prn.c')
-rw-r--r--crypto/err/err_prn.c38
1 files changed, 10 insertions, 28 deletions
diff --git a/crypto/err/err_prn.c b/crypto/err/err_prn.c
index f67cf2e32b..4a82a8880b 100644
--- a/crypto/err/err_prn.c
+++ b/crypto/err/err_prn.c
@@ -27,39 +27,21 @@ void ERR_print_errors_cb(int (*cb) (const char *str, size_t len, void *u),
int line, flags;
while ((l = ERR_get_error_all(&file, &line, &func, &data, &flags)) != 0) {
- char buf[ERR_PRINT_BUF_SIZE], *hex;
- const char *lib, *reason = NULL;
- char rsbuf[256];
- unsigned long r = ERR_GET_REASON(l);
-
- lib = ERR_lib_error_string(l);
-
- /*
- * ERR_reason_error_string() can't safely return system error strings,
- * since it would call openssl_strerror_r(), which needs a buffer for
- * thread safety. So for system errors, we call openssl_strerror_r()
- * directly instead.
- */
- if (ERR_SYSTEM_ERROR(l)) {
- if (openssl_strerror_r(r, rsbuf, sizeof(rsbuf)))
- reason = rsbuf;
- } else {
- reason = ERR_reason_error_string(l);
- }
+ char buf[ERR_PRINT_BUF_SIZE] = "";
+ char *hex = NULL;
+ int offset;
- if (func == NULL)
- func = "unknown function";
- if (reason == NULL) {
- BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
- reason = rsbuf;
- }
if ((flags & ERR_TXT_STRING) == 0)
data = "";
+
hex = openssl_buf2hexstr_sep((const unsigned char *)&tid, sizeof(tid),
'\0');
- BIO_snprintf(buf, sizeof(buf), "%s:error::%s:%s:%s:%s:%d:%s\n",
- hex == NULL ? "<null>" : hex, lib, func, reason, file,
- line, data);
+ BIO_snprintf(buf, sizeof(buf), "%s:", hex == NULL ? "<null>" : hex);
+ offset = strlen(buf);
+ ossl_err_string_int(l, func, buf + offset, sizeof(buf) - offset);
+ offset += strlen(buf + offset);
+ BIO_snprintf(buf + offset, sizeof(buf) - offset, ":%s:%d:%s\n",
+ file, line, data);
OPENSSL_free(hex);
if (cb(buf, strlen(buf), u) <= 0)
break; /* abort outputting the error report */