Skip to content

Commit 6f7a978

Browse files
committed
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: #712 PR-URL: #719 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 50daee7 commit 6f7a978

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/node_crypto.cc

+10
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
587587
Environment* env = Environment::GetCurrent(args);
588588

589589
SecureContext* sc = Unwrap<SecureContext>(args.Holder());
590+
ClearErrorOnReturn clear_error_on_return;
591+
(void) &clear_error_on_return; // Silence compiler warning.
590592

591593
if (args.Length() != 1) {
592594
return env->ThrowTypeError("Bad parameter");
@@ -647,6 +649,8 @@ void SecureContext::AddCRL(const FunctionCallbackInfo<Value>& args) {
647649

648650
void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
649651
SecureContext* sc = Unwrap<SecureContext>(args.Holder());
652+
ClearErrorOnReturn clear_error_on_return;
653+
(void) &clear_error_on_return; // Silence compiler warning.
650654

651655
CHECK_EQ(sc->ca_store_, nullptr);
652656

@@ -682,6 +686,8 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
682686

683687
void SecureContext::SetCiphers(const FunctionCallbackInfo<Value>& args) {
684688
SecureContext* sc = Unwrap<SecureContext>(args.Holder());
689+
ClearErrorOnReturn clear_error_on_return;
690+
(void) &clear_error_on_return; // Silence compiler warning.
685691

686692
if (args.Length() != 1 || !args[0]->IsString()) {
687693
return sc->env()->ThrowTypeError("Bad parameter");
@@ -721,6 +727,8 @@ void SecureContext::SetECDHCurve(const FunctionCallbackInfo<Value>& args) {
721727
void SecureContext::SetDHParam(const FunctionCallbackInfo<Value>& args) {
722728
SecureContext* sc = Unwrap<SecureContext>(args.This());
723729
Environment* env = sc->env();
730+
ClearErrorOnReturn clear_error_on_return;
731+
(void) &clear_error_on_return; // Silence compiler warning.
724732

725733
// Auto DH is not supported in openssl 1.0.1, so dhparam needs
726734
// to be specifed explicitly
@@ -825,6 +833,8 @@ void SecureContext::LoadPKCS12(const FunctionCallbackInfo<Value>& args) {
825833
bool ret = false;
826834

827835
SecureContext* sc = Unwrap<SecureContext>(args.Holder());
836+
ClearErrorOnReturn clear_error_on_return;
837+
(void) &clear_error_on_return; // Silence compiler warning.
828838

829839
if (args.Length() < 1) {
830840
return env->ThrowTypeError("Bad parameter");

0 commit comments

Comments
 (0)