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 abe3dc4

Browse filesBrowse files
davidbenevanlucas
authored andcommitted
crypto: make Hash 1.1.0-compatible
OpenSSL 1.1.0 requires EVP_MD_CTX be heap-allocated. PR-URL: #16130 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rod Vagg <rod@vagg.org>
1 parent 59acd27 commit abe3dc4
Copy full SHA for abe3dc4

File tree

Expand file treeCollapse file tree

2 files changed

+20
-15
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-15
lines changed
Open diff view settings
Collapse file

‎src/node_crypto.cc‎

Copy file name to clipboardExpand all lines: src/node_crypto.cc
+16-7Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ static int X509_up_ref(X509* cert) {
204204
CRYPTO_add(&cert->references, 1, CRYPTO_LOCK_X509);
205205
return 1;
206206
}
207+
208+
#define EVP_MD_CTX_new EVP_MD_CTX_create
209+
#define EVP_MD_CTX_free EVP_MD_CTX_destroy
207210
#endif // OPENSSL_VERSION_NUMBER < 0x10100000L
208211

209212
// Subject DER of CNNIC ROOT CA and CNNIC EV ROOT CA are taken from
@@ -3937,6 +3940,11 @@ void Hmac::HmacDigest(const FunctionCallbackInfo<Value>& args) {
39373940
}
39383941

39393942

3943+
Hash::~Hash() {
3944+
EVP_MD_CTX_free(mdctx_);
3945+
}
3946+
3947+
39403948
void Hash::Initialize(Environment* env, v8::Local<v8::Object> target) {
39413949
Local<FunctionTemplate> t = env->NewFunctionTemplate(New);
39423950

@@ -3966,20 +3974,22 @@ bool Hash::HashInit(const char* hash_type) {
39663974
const EVP_MD* md = EVP_get_digestbyname(hash_type);
39673975
if (md == nullptr)
39683976
return false;
3969-
EVP_MD_CTX_init(&mdctx_);
3970-
if (EVP_DigestInit_ex(&mdctx_, md, nullptr) <= 0) {
3977+
mdctx_ = EVP_MD_CTX_new();
3978+
if (mdctx_ == nullptr ||
3979+
EVP_DigestInit_ex(mdctx_, md, nullptr) <= 0) {
3980+
EVP_MD_CTX_free(mdctx_);
3981+
mdctx_ = nullptr;
39713982
return false;
39723983
}
3973-
initialised_ = true;
39743984
finalized_ = false;
39753985
return true;
39763986
}
39773987

39783988

39793989
bool Hash::HashUpdate(const char* data, int len) {
3980-
if (!initialised_)
3990+
if (mdctx_ == nullptr)
39813991
return false;
3982-
EVP_DigestUpdate(&mdctx_, data, len);
3992+
EVP_DigestUpdate(mdctx_, data, len);
39833993
return true;
39843994
}
39853995

@@ -4023,8 +4033,7 @@ void Hash::HashDigest(const FunctionCallbackInfo<Value>& args) {
40234033
unsigned char md_value[EVP_MAX_MD_SIZE];
40244034
unsigned int md_len;
40254035

4026-
EVP_DigestFinal_ex(&hash->mdctx_, md_value, &md_len);
4027-
EVP_MD_CTX_cleanup(&hash->mdctx_);
4036+
EVP_DigestFinal_ex(hash->mdctx_, md_value, &md_len);
40284037
hash->finalized_ = true;
40294038

40304039
Local<Value> error;
Collapse file

‎src/node_crypto.h‎

Copy file name to clipboardExpand all lines: src/node_crypto.h
+4-8Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,7 @@ class Hmac : public BaseObject {
524524

525525
class Hash : public BaseObject {
526526
public:
527-
~Hash() override {
528-
if (!initialised_)
529-
return;
530-
EVP_MD_CTX_cleanup(&mdctx_);
531-
}
527+
~Hash() override;
532528

533529
static void Initialize(Environment* env, v8::Local<v8::Object> target);
534530

@@ -542,13 +538,13 @@ class Hash : public BaseObject {
542538

543539
Hash(Environment* env, v8::Local<v8::Object> wrap)
544540
: BaseObject(env, wrap),
545-
initialised_(false) {
541+
mdctx_(nullptr),
542+
finalized_(false) {
546543
MakeWeak<Hash>(this);
547544
}
548545

549546
private:
550-
EVP_MD_CTX mdctx_; /* coverity[member_decl] */
551-
bool initialised_;
547+
EVP_MD_CTX* mdctx_;
552548
bool finalized_;
553549
};
554550

0 commit comments

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