From 6cf8895bf130b90daabd534527ce1a2a93fa20d0 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Wed, 21 Nov 2018 23:04:00 -0500 Subject: [PATCH] Add additional assert to FixedSizeAllocatorWithCleanup (GH #745) This assert checks the array we return to the caller is large enough. Spoiler alert... it is not always large enough, like on 64-bit AIX. The linker on AIX appears to align smaller than 8-bytes --- secblock.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/secblock.h b/secblock.h index a9e350a6..4ad7c381 100644 --- a/secblock.h +++ b/secblock.h @@ -500,7 +500,10 @@ private: // for a large T, and that is what PAD achieves. T* GetAlignedArray() { T* p_array = (T*)(void*)(((byte*)m_array) + (0-(size_t)m_array)%16); + // Verify the 16-byte alignment CRYPTOPP_ASSERT(IsAlignedOn(p_array, 16)); + // Verify allocated array with pad is large enough. + CRYPTOPP_ASSERT(p_array+S <= m_array+(S+PAD)); return p_array; } // PAD is elements, not bytes, and rounded up to ensure no overflow.