Skip to content

Commit a64aa44

Browse files
Tom AtkinsonMylesBorins
Tom Atkinson
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: #9469 Fixes: #12033 PR-URL: #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 d8b71be commit a64aa44

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/node_crypto.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,9 @@ inline bool CertIsStartComOrWoSign(X509_NAME* name) {
27602760
startcom_wosign_data = dn.data;
27612761
startcom_wosign_name = d2i_X509_NAME(nullptr, &startcom_wosign_data,
27622762
dn.len);
2763-
if (X509_NAME_cmp(name, startcom_wosign_name) == 0)
2763+
int cmp = X509_NAME_cmp(name, startcom_wosign_name);
2764+
X509_NAME_free(startcom_wosign_name);
2765+
if (cmp == 0)
27642766
return true;
27652767
}
27662768

@@ -2805,8 +2807,10 @@ inline CheckResult CheckWhitelistedServerCert(X509_STORE_CTX* ctx) {
28052807
}
28062808

28072809
X509* leaf_cert = sk_X509_value(chain, 0);
2808-
if (!CheckStartComOrWoSign(root_name, leaf_cert))
2810+
if (!CheckStartComOrWoSign(root_name, leaf_cert)) {
2811+
sk_X509_pop_free(chain, X509_free);
28092812
return CHECK_CERT_REVOKED;
2813+
}
28102814

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

0 commit comments

Comments
 (0)