Skip to content

Commit 40ae307

Browse files
addaleaxjasnell
authored andcommitted
src: avoid possible race during NodeBIO initialization
PR-URL: #21984 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 987dc07 commit 40ae307

4 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/node_crypto.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5141,6 +5141,8 @@ void InitCryptoOnce() {
51415141
ERR_load_ENGINE_strings();
51425142
ENGINE_load_builtin_engines();
51435143
#endif // !OPENSSL_NO_ENGINE
5144+
5145+
NodeBIO::GetMethod();
51445146
}
51455147

51465148

src/node_crypto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx);
9797

9898
extern void UseExtraCaCerts(const std::string& file);
9999

100+
void InitCryptoOnce();
101+
100102
class SecureContext : public BaseObject {
101103
public:
102104
~SecureContext() override {

src/node_crypto_bio.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ const BIO_METHOD* NodeBIO::GetMethod() {
247247

248248
return &method;
249249
#else
250+
// This is called from InitCryptoOnce() to avoid race conditions during
251+
// initialization.
250252
static BIO_METHOD* method = nullptr;
251253

252254
if (method == nullptr) {

src/node_crypto_bio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ class NodeBIO : public MemoryRetainer {
164164
int eof_return_ = -1;
165165
Buffer* read_head_ = nullptr;
166166
Buffer* write_head_ = nullptr;
167+
168+
friend void node::crypto::InitCryptoOnce();
167169
};
168170

169171
} // namespace crypto

0 commit comments

Comments
 (0)