From 3055edec2f1046dad9a859733eebcffc01bcf3ff Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 25 Oct 2021 14:39:34 -0400 Subject: [PATCH] crypto: add missing null check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add null check before using result of ERR_reason_error_string. Coverity reported as an issue and we seem to do a null check in other places we call the function. Signed-off-by: Michael Dawson PR-URL: https://github.com/nodejs/node/pull/40598 Reviewed-By: James M Snell Reviewed-By: Colin Ihrig Reviewed-By: Tobias Nießen Reviewed-By: Mohammed Keyvanzadeh --- src/crypto/crypto_context.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/crypto/crypto_context.cc b/src/crypto/crypto_context.cc index 4ecd8a8c4204fc..739b559c3b7b22 100644 --- a/src/crypto/crypto_context.cc +++ b/src/crypto/crypto_context.cc @@ -1037,6 +1037,8 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo& args) { // TODO(@jasnell): Should this use ThrowCryptoError? unsigned long err = ERR_get_error(); // NOLINT(runtime/int) const char* str = ERR_reason_error_string(err); + str = str != nullptr ? str : "Unknown error"; + return env->ThrowError(str); } }