Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 9b1683e

Browse files
Tom Atkinsonkevinsawicki
authored andcommitted
crypto: fix memory leak if certificate is revoked
The additional validity checks applied to StartCom and WoSign certificates failed to free memory before returning. Refs: nodejs/node#9469 Fixes: nodejs/node#12033 PR-URL: nodejs/node#12089 Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Shigeki Ohtsu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 943cb37 commit 9b1683e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/node_crypto.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,9 @@ inline bool CertIsStartComOrWoSign(X509_NAME* name) {
27672767
startcom_wosign_data = dn.data;
27682768
startcom_wosign_name = d2i_X509_NAME(nullptr, &startcom_wosign_data,
27692769
dn.len);
2770-
if (X509_NAME_cmp(name, startcom_wosign_name) == 0)
2770+
int cmp = X509_NAME_cmp(name, startcom_wosign_name);
2771+
X509_NAME_free(startcom_wosign_name);
2772+
if (cmp == 0)
27712773
return true;
27722774
}
27732775

@@ -2812,8 +2814,10 @@ inline CheckResult CheckWhitelistedServerCert(X509_STORE_CTX* ctx) {
28122814
}
28132815

28142816
X509* leaf_cert = sk_X509_value(chain, 0);
2815-
if (!CheckStartComOrWoSign(root_name, leaf_cert))
2817+
if (!CheckStartComOrWoSign(root_name, leaf_cert)) {
2818+
sk_X509_pop_free(chain, X509_free);
28162819
return CHECK_CERT_REVOKED;
2820+
}
28172821

28182822
// When the cert is issued from either CNNNIC ROOT CA or CNNNIC EV
28192823
// ROOT CA, check a hash of its leaf cert if it is in the whitelist.

0 commit comments

Comments
 (0)