mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
src: avoid X509_free in loops in crypto_x509.cc
Use X509Pointer objects for automatic memory management instead. PR-URL: https://github.com/nodejs/node/pull/44855 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
e2ca29f673
commit
e84e2e6c85
1 file changed
+7
-9
@@ -699,15 +699,14 @@ void SecureContext::AddCACert(const FunctionCallbackInfo<Value>& args) {
|
||||
return;
|
||||
|
||||
X509_STORE* cert_store = SSL_CTX_get_cert_store(sc->ctx_.get());
|
||||
while (X509* x509 = PEM_read_bio_X509_AUX(
|
||||
bio.get(), nullptr, NoPasswordCallback, nullptr)) {
|
||||
while (X509Pointer x509 = X509Pointer(PEM_read_bio_X509_AUX(
|
||||
bio.get(), nullptr, NoPasswordCallback, nullptr))) {
|
||||
if (cert_store == root_cert_store) {
|
||||
cert_store = NewRootCertStore();
|
||||
SSL_CTX_set_cert_store(sc->ctx_.get(), cert_store);
|
||||
}
|
||||
X509_STORE_add_cert(cert_store, x509);
|
||||
SSL_CTX_add_client_CA(sc->ctx_.get(), x509);
|
||||
X509_free(x509);
|
||||
X509_STORE_add_cert(cert_store, x509.get());
|
||||
SSL_CTX_add_client_CA(sc->ctx_.get(), x509.get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1311,10 +1310,9 @@ unsigned long AddCertsFromFile( // NOLINT(runtime/int)
|
||||
if (!bio)
|
||||
return ERR_get_error();
|
||||
|
||||
while (X509* x509 =
|
||||
PEM_read_bio_X509(bio.get(), nullptr, NoPasswordCallback, nullptr)) {
|
||||
X509_STORE_add_cert(store, x509);
|
||||
X509_free(x509);
|
||||
while (X509Pointer x509 = X509Pointer(PEM_read_bio_X509(
|
||||
bio.get(), nullptr, NoPasswordCallback, nullptr))) {
|
||||
X509_STORE_add_cert(store, x509.get());
|
||||
}
|
||||
|
||||
unsigned long err = ERR_peek_error(); // NOLINT(runtime/int)
|
||||
|
||||
Reference in new issue
Block a user