diff --git a/src/common/crypto.c b/src/common/crypto.c
index c7e5d4587f307ec7283baee5200c00c0c65534bc..0cc393be3e8908618a76c340bfe15b7a79f05df9 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -156,6 +156,8 @@ crypto_log_errors(int severity, const char *doing)
     lib = (const char*)ERR_lib_error_string(err);
     func = (const char*)ERR_func_error_string(err);
     if (!msg) msg = "(null)";
+    if (!lib) lib = "(null)";
+    if (!func) func = "(null)";
     if (doing) {
       log(severity, LD_CRYPTO, "crypto error while %s: %s (in %s:%s)",
           doing, msg, lib, func);