Skip to content

Commit 6857ee8

Browse files
tniessenRafaelGSS
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 <panva.ip@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 1cdccbc commit 6857ee8

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

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

0 commit comments

Comments
 (0)