Skip to content

Commit 43343fe

Browse files
tniessenFyko
authored andcommitted
src: make minor improvements to SecureBuffer
Remove an unnecessary static_cast<char*>(). Use OPENSSL_secure_zalloc() instead of OPENSSL_secure_malloc() + memset(). Update the comment describing the function which predates support for OpenSSL's secure heap. PR-URL: nodejs#44302 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent f1c6590 commit 43343fe

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/crypto/crypto_util.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -673,22 +673,21 @@ CryptoJobMode GetCryptoJobMode(v8::Local<v8::Value> args) {
673673
}
674674

675675
namespace {
676-
// SecureBuffer uses openssl to allocate a Uint8Array using
677-
// OPENSSL_secure_malloc. Because we do not yet actually
678-
// make use of secure heap, this has the same semantics as
676+
// SecureBuffer uses OPENSSL_secure_malloc to allocate a Uint8Array.
677+
// Without --secure-heap, OpenSSL's secure heap is disabled,
678+
// in which case this has the same semantics as
679679
// using OPENSSL_malloc. However, if the secure heap is
680680
// initialized, SecureBuffer will automatically use it.
681681
void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
682682
CHECK(args[0]->IsUint32());
683683
Environment* env = Environment::GetCurrent(args);
684684
uint32_t len = args[0].As<Uint32>()->Value();
685-
char* data = static_cast<char*>(OPENSSL_secure_malloc(len));
685+
void* data = OPENSSL_secure_zalloc(len);
686686
if (data == nullptr) {
687687
// There's no memory available for the allocation.
688688
// Return nothing.
689689
return;
690690
}
691-
memset(data, 0, len);
692691
std::shared_ptr<BackingStore> store =
693692
ArrayBuffer::NewBackingStore(
694693
data,

0 commit comments

Comments
 (0)