Skip to content

Commit 2f3502f

Browse files
tniessenjuanarbol
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: #44302 Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent f717c1e commit 2f3502f

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
@@ -689,22 +689,21 @@ CryptoJobMode GetCryptoJobMode(v8::Local<v8::Value> args) {
689689
}
690690

691691
namespace {
692-
// SecureBuffer uses openssl to allocate a Uint8Array using
693-
// OPENSSL_secure_malloc. Because we do not yet actually
694-
// make use of secure heap, this has the same semantics as
692+
// SecureBuffer uses OPENSSL_secure_malloc to allocate a Uint8Array.
693+
// Without --secure-heap, OpenSSL's secure heap is disabled,
694+
// in which case this has the same semantics as
695695
// using OPENSSL_malloc. However, if the secure heap is
696696
// initialized, SecureBuffer will automatically use it.
697697
void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
698698
CHECK(args[0]->IsUint32());
699699
Environment* env = Environment::GetCurrent(args);
700700
uint32_t len = args[0].As<Uint32>()->Value();
701-
char* data = static_cast<char*>(OPENSSL_secure_malloc(len));
701+
void* data = OPENSSL_secure_zalloc(len);
702702
if (data == nullptr) {
703703
// There's no memory available for the allocation.
704704
// Return nothing.
705705
return;
706706
}
707-
memset(data, 0, len);
708707
std::shared_ptr<BackingStore> store =
709708
ArrayBuffer::NewBackingStore(
710709
data,

0 commit comments

Comments
 (0)