Skip to content

Commit ba4f0e4

Browse files
tniessentargos
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 ffa1f01 commit ba4f0e4

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/crypto/crypto_util.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,22 +701,21 @@ CryptoJobMode GetCryptoJobMode(v8::Local<v8::Value> args) {
701701
}
702702

703703
namespace {
704-
// SecureBuffer uses openssl to allocate a Uint8Array using
705-
// OPENSSL_secure_malloc. Because we do not yet actually
706-
// make use of secure heap, this has the same semantics as
704+
// SecureBuffer uses OPENSSL_secure_malloc to allocate a Uint8Array.
705+
// Without --secure-heap, OpenSSL's secure heap is disabled,
706+
// in which case this has the same semantics as
707707
// using OPENSSL_malloc. However, if the secure heap is
708708
// initialized, SecureBuffer will automatically use it.
709709
void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
710710
CHECK(args[0]->IsUint32());
711711
Environment* env = Environment::GetCurrent(args);
712712
uint32_t len = args[0].As<Uint32>()->Value();
713-
char* data = static_cast<char*>(OPENSSL_secure_malloc(len));
713+
void* data = OPENSSL_secure_zalloc(len);
714714
if (data == nullptr) {
715715
// There's no memory available for the allocation.
716716
// Return nothing.
717717
return;
718718
}
719-
memset(data, 0, len);
720719
std::shared_ptr<BackingStore> store =
721720
ArrayBuffer::NewBackingStore(
722721
data,

0 commit comments

Comments
 (0)