Skip to content

Commit b2ac7a7

Browse files
addaleaxrvagg
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 d85b0a3 commit b2ac7a7

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

src/node_crypto.cc

+2
Original file line numberDiff line numberDiff line change
@@ -5126,6 +5126,8 @@ void InitCryptoOnce() {
51265126
ERR_load_ENGINE_strings();
51275127
ENGINE_load_builtin_engines();
51285128
#endif // !OPENSSL_NO_ENGINE
5129+
5130+
NodeBIO::GetMethod();
51295131
}
51305132

51315133

src/node_crypto.h

+2
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

+2
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

+2
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)