From 6f7a9784eaef82a1aa6cf53bbbd7224c446876a0 Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 5 Feb 2015 00:01:11 +0300 Subject: [PATCH] crypto: clear error on return in TLS methods Methods like `X509_STORE_add_cert` may push errors onto OpenSSL's error stack. Ensure that they won't pop up in a different places like `tls_wrap.cc`. Fix: https://github.com/iojs/io.js/issues/712 PR-URL: https://github.com/iojs/io.js/pull/719 Reviewed-By: Ben Noordhuis --- src/node_crypto.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/node_crypto.cc b/src/node_crypto.cc index d0526615a8..5432eaeccc 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -587,6 +587,8 @@ void SecureContext::AddCACert(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); SecureContext* sc = Unwrap(args.Holder()); + ClearErrorOnReturn clear_error_on_return; + (void) &clear_error_on_return; // Silence compiler warning. if (args.Length() != 1) { return env->ThrowTypeError("Bad parameter"); @@ -647,6 +649,8 @@ void SecureContext::AddCRL(const FunctionCallbackInfo& args) { void SecureContext::AddRootCerts(const FunctionCallbackInfo& args) { SecureContext* sc = Unwrap(args.Holder()); + ClearErrorOnReturn clear_error_on_return; + (void) &clear_error_on_return; // Silence compiler warning. CHECK_EQ(sc->ca_store_, nullptr); @@ -682,6 +686,8 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo& args) { void SecureContext::SetCiphers(const FunctionCallbackInfo& args) { SecureContext* sc = Unwrap(args.Holder()); + ClearErrorOnReturn clear_error_on_return; + (void) &clear_error_on_return; // Silence compiler warning. if (args.Length() != 1 || !args[0]->IsString()) { return sc->env()->ThrowTypeError("Bad parameter"); @@ -721,6 +727,8 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo& args) { void SecureContext::SetDHParam(const FunctionCallbackInfo& args) { SecureContext* sc = Unwrap(args.This()); Environment* env = sc->env(); + ClearErrorOnReturn clear_error_on_return; + (void) &clear_error_on_return; // Silence compiler warning. // Auto DH is not supported in openssl 1.0.1, so dhparam needs // to be specifed explicitly @@ -825,6 +833,8 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo& args) { bool ret = false; SecureContext* sc = Unwrap(args.Holder()); + ClearErrorOnReturn clear_error_on_return; + (void) &clear_error_on_return; // Silence compiler warning. if (args.Length() < 1) { return env->ThrowTypeError("Bad parameter");