aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-08-22 11:03:33 -0400
committerNick Mathewson <nickm@torproject.org>2018-08-22 12:36:25 -0400
commit7c5339677fd4d524a95bc8c18af223f710ca94e2 (patch)
treef5373e7f430c69081901a88a58dfc1e1f3c4feb7 /src
parent8148c0717dc6b05b0cda18ade94e03ed947bc7a3 (diff)
downloadtor-7c5339677fd4d524a95bc8c18af223f710ca94e2.tar.gz
tor-7c5339677fd4d524a95bc8c18af223f710ca94e2.zip
Log error strings in crypto_nss_log_errors().
I'll need this for debugging.
Diffstat (limited to 'src')
-rw-r--r--src/lib/crypt_ops/crypto_nss_mgt.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/lib/crypt_ops/crypto_nss_mgt.c b/src/lib/crypt_ops/crypto_nss_mgt.c
index 89ef019218..85b18e00cd 100644
--- a/src/lib/crypt_ops/crypto_nss_mgt.c
+++ b/src/lib/crypt_ops/crypto_nss_mgt.c
@@ -14,6 +14,7 @@
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
+#include "lib/string/printf.h"
DISABLE_GCC_WARNING(strict-prototypes)
#include <nss.h>
@@ -74,11 +75,20 @@ void
crypto_nss_log_errors(int severity, const char *doing)
{
PRErrorCode code = PR_GetError();
- /* XXXX how do I convert errors to strings? */
+ const char *string = PORT_ErrorToString(code);
+ const char *name = PORT_ErrorToName(code);
+ char buf[16];
+ if (!string)
+ string = "<unrecognized>";
+ if (!name) {
+ tor_snprintf(buf, sizeof(buf), "%d", code);
+ name = buf;
+ }
if (doing) {
- tor_log(severity, LD_CRYPTO, "NSS error %u while %s", code, doing);
+ tor_log(severity, LD_CRYPTO, "NSS error %s while %s: %s",
+ name, doing, string);
} else {
- tor_log(severity, LD_CRYPTO, "NSS error %u", code);
+ tor_log(severity, LD_CRYPTO, "NSS error %s: %s", name, string);
}
}