Skip to content

Commit f613538

Browse files
committed
fixup! crypto: add guards and adjust tests for BoringSSL
Signed-off-by: Filip Skokan <[email protected]>
1 parent c277f98 commit f613538

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

deps/ncrypto/ncrypto.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ DataPointer DataPointer::SecureAlloc(size_t len) {
147147
#ifndef OPENSSL_IS_BORINGSSL
148148
auto ptr = OPENSSL_secure_zalloc(len);
149149
if (ptr == nullptr) return {};
150-
return DataPointer(ptr, len, true);
150+
// OPENSSL_secure_zalloc transparently falls back to a regular allocation
151+
// when the secure heap is not initialized or is exhausted. Reflect the
152+
// actual provenance of the pointer so that reset() routes to the correct
153+
// free function (OPENSSL_secure_clear_free vs. OPENSSL_clear_free) and
154+
// callers of isSecure() get a truthful answer.
155+
return DataPointer(ptr, len, CRYPTO_secure_allocated(ptr) == 1);
151156
#else
152157
// BoringSSL does not implement the OPENSSL_secure_zalloc API.
153158
auto ptr = OPENSSL_malloc(len);

src/crypto/crypto_util.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,6 @@ void SecureBuffer(const FunctionCallbackInfo<Value>& args) {
736736
uint32_t len = args[0].As<Uint32>()->Value();
737737

738738
auto data = DataPointer::SecureAlloc(len);
739-
CHECK(data.isSecure());
740739
if (!data) {
741740
return THROW_ERR_OPERATION_FAILED(env, "Allocation failed");
742741
}

0 commit comments

Comments
 (0)