Skip to content

Commit

Permalink
src: avoid possible race during NodeBIO initialization
Browse files Browse the repository at this point in the history
PR-URL: #21984
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
addaleax authored and rvagg committed Aug 13, 2018
1 parent 4590a1c commit 28d4d5f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5126,6 +5126,8 @@ void InitCryptoOnce() {
ERR_load_ENGINE_strings();
ENGINE_load_builtin_engines();
#endif // !OPENSSL_NO_ENGINE

NodeBIO::GetMethod();
}


Expand Down
2 changes: 2 additions & 0 deletions src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ extern int VerifyCallback(int preverify_ok, X509_STORE_CTX* ctx);

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

void InitCryptoOnce();

class SecureContext : public BaseObject {
public:
~SecureContext() override {
Expand Down
2 changes: 2 additions & 0 deletions src/node_crypto_bio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ const BIO_METHOD* NodeBIO::GetMethod() {

return &method;
#else
// This is called from InitCryptoOnce() to avoid race conditions during
// initialization.
static BIO_METHOD* method = nullptr;

if (method == nullptr) {
Expand Down
2 changes: 2 additions & 0 deletions src/node_crypto_bio.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class NodeBIO : public MemoryRetainer {
int eof_return_ = -1;
Buffer* read_head_ = nullptr;
Buffer* write_head_ = nullptr;

friend void node::crypto::InitCryptoOnce();
};

} // namespace crypto
Expand Down

0 comments on commit 28d4d5f

Please sign in to comment.