From 78c33f3f5e9770623b357f1d7d1ba0952d7461ee Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 11 Aug 2022 23:43:36 +0000 Subject: [PATCH] Switch to C23's memset_explicit(). Test: treehugger Change-Id: Ib6ef45cedaf95fa251d0b03de0f14701f910d063 --- KeyBuffer.h | 18 ++---------------- Keystore.cpp | 2 +- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/KeyBuffer.h b/KeyBuffer.h index a68311f..4468220 100644 --- a/KeyBuffer.h +++ b/KeyBuffer.h @@ -17,32 +17,18 @@ #ifndef ANDROID_VOLD_KEYBUFFER_H #define ANDROID_VOLD_KEYBUFFER_H -#include +#include #include #include namespace android { namespace vold { -/** - * Variant of memset() that should never be optimized away. Borrowed from keymaster code. - */ -#ifdef __clang__ -#define OPTNONE __attribute__((optnone)) -#else // not __clang__ -#define OPTNONE __attribute__((optimize("O0"))) -#endif // not __clang__ -inline OPTNONE void* memset_s(void* s, int c, size_t n) { - if (!s) return s; - return memset(s, c, n); -} -#undef OPTNONE - // Allocator that delegates useful work to standard one but zeroes data before deallocating. class ZeroingAllocator : public std::allocator { public: void deallocate(pointer p, size_type n) { - memset_s(p, 0, n); + memset_explicit(p, 0, n); std::allocator::deallocate(p, n); } }; diff --git a/Keystore.cpp b/Keystore.cpp index d993b0d..6040f2d 100644 --- a/Keystore.cpp +++ b/Keystore.cpp @@ -48,7 +48,7 @@ KeystoreOperation::~KeystoreOperation() { } static void zeroize_vector(std::vector& vec) { - memset_s(vec.data(), 0, vec.size()); + memset_explicit(vec.data(), 0, vec.size()); } static bool logKeystore2ExceptionIfPresent(::ndk::ScopedAStatus& rc, const std::string& func_name) {