From 3a01eccf92ccc906d63dbed91bd91ab7418724bc Mon Sep 17 00:00:00 2001 From: beck <> Date: Tue, 7 Feb 2017 03:11:11 +0000 Subject: Add file and line to the LibreSSL error strings sine we are no longer in 1989, VMS, or MS/DOS and we all run Brobdingnagian C compilers that have can now be counted on to achieve this level of sophistication nearly everywhere. ok jsing@ --- src/lib/libcrypto/err/err.c | 21 +++++++++++++++++---- src/lib/libcrypto/err/err_prn.c | 6 +++--- 2 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index 292805433d..dcf725fd64 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err.c,v 1.42 2017/01/29 17:49:23 beck Exp $ */ +/* $OpenBSD: err.c,v 1.43 2017/02/07 03:11:11 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -862,8 +862,9 @@ void ERR_error_string_n(unsigned long e, char *buf, size_t len) { char lsbuf[30], fsbuf[30], rsbuf[30]; - const char *ls, *fs, *rs; - int l, f, r, ret; + const char *ls, *fs, *rs, *file, *data; + int l, f, r, ret, line, flags; + l = ERR_GET_LIB(e); f = ERR_GET_FUNC(e); @@ -886,7 +887,19 @@ ERR_error_string_n(unsigned long e, char *buf, size_t len) rs = rsbuf; } - ret = snprintf(buf, len, "error:%08lX:%s:%s:%s", e, ls, fs, rs); + if (ERR_get_error_line_data(&file, &line, &data, &flags) != 0) { + const char *filename; + + if ((filename = strrchr(file, '/')) != NULL) + filename++; + else + filename = file; + + ret = snprintf(buf, len, "error:%08lX:%s:%s:%s:%s:%d", e, ls, + fs, rs, filename, line); + } else + ret = snprintf(buf, len, "error:%08lX:%s:%s:%s", e, ls, fs, rs); + if (ret == -1) return; /* can't happen, and can't do better if it does */ if (ret >= len) { diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c index 021bcd5d1d..6a3062a89a 100644 --- a/src/lib/libcrypto/err/err_prn.c +++ b/src/lib/libcrypto/err/err_prn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err_prn.c,v 1.16 2014/07/11 08:44:48 jsing Exp $ */ +/* $OpenBSD: err_prn.c,v 1.17 2017/02/07 03:11:11 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -80,8 +80,8 @@ ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), void *u) while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0) { ERR_error_string_n(l, buf, sizeof buf); - (void) snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", es, - buf, file, line, (flags & ERR_TXT_STRING) ? data : ""); + (void) snprintf(buf2, sizeof(buf2), "%lu:%s:%s\n", es, + buf, (flags & ERR_TXT_STRING) ? data : ""); if (cb(buf2, strlen(buf2), u) <= 0) break; /* abort outputting the error report */ } -- cgit v1.2.3-55-g6feb