GeezerVison is showing github.com — src: avoid possible race during NodeBIO initialization · nodejs/node@b2ac7a7
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_crypto.cc +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5126,6 +5126,8 @@ void InitCryptoOnce() { |
5126 | 5126 | ERR_load_ENGINE_strings(); |
5127 | 5127 | ENGINE_load_builtin_engines(); |
5128 | 5128 | #endif // !OPENSSL_NO_ENGINE |
| 5129 | + |
| 5130 | + NodeBIO::GetMethod(); |
5129 | 5131 | } |
5130 | 5132 |
|
5131 | 5133 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_crypto.h +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -97,6 +97,8 @@ extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx); |
97 | 97 |
|
98 | 98 | extern void UseExtraCaCerts(const std::string& file); |
99 | 99 |
|
| 100 | +void InitCryptoOnce(); |
| 101 | + |
100 | 102 | class SecureContext : public BaseObject { |
101 | 103 | public: |
102 | 104 | ~SecureContext() override { |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_crypto_bio.cc +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -247,6 +247,8 @@ const BIO_METHOD* NodeBIO::GetMethod() { |
247 | 247 |
|
248 | 248 | return &method; |
249 | 249 | #else |
| 250 | + // This is called from InitCryptoOnce() to avoid race conditions during |
| 251 | + // initialization. |
250 | 252 | static BIO_METHOD* method = nullptr; |
251 | 253 |
|
252 | 254 | if (method == nullptr) { |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_crypto_bio.h +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -164,6 +164,8 @@ class NodeBIO : public MemoryRetainer { |
164 | 164 | int eof_return_ = -1; |
165 | 165 | Buffer* read_head_ = nullptr; |
166 | 166 | Buffer* write_head_ = nullptr; |
| 167 | + |
| 168 | + friend void node::crypto::InitCryptoOnce(); |
167 | 169 | }; |
168 | 170 |
|
169 | 171 | } // namespace crypto |
|