Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bf882fb

Browse filesBrowse files
AdamMajerMylesBorins
authored andcommitted
crypto: Use reference count to manage cert_store
Setting reference count at the time of setting cert_store instead of trying to manage it by modifying internal states in destructor. PR-URL: #9409 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Shigeki Ohtsu <ohtsu@ohtsu.org>
1 parent d3a7fb8 commit bf882fb
Copy full SHA for bf882fb

File tree

Expand file treeCollapse file tree

2 files changed

+2
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+2
-7
lines changed
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,8 @@ void SecureContext::AddRootCerts(const FunctionCallbackInfo<Value>& args) {
785785
}
786786

787787
sc->ca_store_ = root_cert_store;
788+
// Increment reference count so global store is not deleted along with CTX.
789+
CRYPTO_add(&root_cert_store->references, 1, CRYPTO_LOCK_X509_STORE);
788790
SSL_CTX_set_cert_store(sc->ctx_, sc->ca_store_);
789791
}
790792

Collapse file

‎src/node_crypto.h‎

Copy file name to clipboardExpand all lines: src/node_crypto.h
-7Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,6 @@ class SecureContext : public BaseObject {
140140
void FreeCTXMem() {
141141
if (ctx_) {
142142
env()->isolate()->AdjustAmountOfExternalAllocatedMemory(-kExternalSize);
143-
if (ctx_->cert_store == root_cert_store) {
144-
// SSL_CTX_free() will attempt to free the cert_store as well.
145-
// Since we want our root_cert_store to stay around forever
146-
// we just clear the field. Hopefully OpenSSL will not modify this
147-
// struct in future versions.
148-
ctx_->cert_store = nullptr;
149-
}
150143
SSL_CTX_free(ctx_);
151144
if (cert_ != nullptr)
152145
X509_free(cert_);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.