From df84be7b7f4a0b6665dfc88f3d30b69e8d2af37c Mon Sep 17 00:00:00 2001 From: Wendigo <84196391+wendig0x@users.noreply.github.com> Date: Thu, 24 Aug 2023 19:38:43 +0300 Subject: [PATCH] Fixed the memory burn Fixed the memory clearing function a little bit --- src/Common/Tcdefs.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Common/Tcdefs.h b/src/Common/Tcdefs.h index ff67bc93..9a4071bf 100644 --- a/src/Common/Tcdefs.h +++ b/src/Common/Tcdefs.h @@ -407,7 +407,17 @@ extern BOOLEAN VC_KeAreAllApcsDisabled (VOID); #if defined(_WIN32) && !defined(_UEFI) #define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); size_t burnc = size; RtlSecureZeroMemory (mem, size); while (burnc--) *burnm++ = 0; } while (0) #else -#define burn(mem,size) do { volatile char *burnm = (volatile char *)(mem); int burnc = size; while (burnc--) *burnm++ = 0; } while (0) +#define burn(mem, size) do { \ + volatile char *burnm = (volatile char *)(mem); \ + size_t burnc = (size_t)(size); \ + if (burnm && burnc > 0) { \ + for (size_t i = 0; i < burnc; i++) { \ + if (&burnm[i] >= mem && &burnm[i] < mem + size) { \ + burnm[i] = 0; \ + } \ + } \ + } \ +} while (0) #endif #define volatile_memcpy(d,s,size) do { volatile char *destm = (volatile char *)(d); volatile char *srcm = (volatile char *)(s); size_t memc = size; while (memc--) *destm++ = *srcm++; } while (0)