Merge "Switch to C23's memset_explicit()." am: dd7cfa9e15
am: 6e9353e630
Original change: https://android-review.googlesource.com/c/platform/system/vold/+/2184090 Change-Id: I11c96a825838d6731a970b2f6f29e3e7d8623274 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
f90e6ab299
2 changed files with 3 additions and 17 deletions
18
KeyBuffer.h
18
KeyBuffer.h
|
@ -17,32 +17,18 @@
|
|||
#ifndef ANDROID_VOLD_KEYBUFFER_H
|
||||
#define ANDROID_VOLD_KEYBUFFER_H
|
||||
|
||||
#include <cstring>
|
||||
#include <string.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
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<char> {
|
||||
public:
|
||||
void deallocate(pointer p, size_type n) {
|
||||
memset_s(p, 0, n);
|
||||
memset_explicit(p, 0, n);
|
||||
std::allocator<char>::deallocate(p, n);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -48,7 +48,7 @@ KeystoreOperation::~KeystoreOperation() {
|
|||
}
|
||||
|
||||
static void zeroize_vector(std::vector<uint8_t>& 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) {
|
||||
|
|
Loading…
Reference in a new issue