From 5b5bdb1bd1b6cce5f0a57fc3d6531fc26d31cde7 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 16 Mar 2015 20:59:59 -0400 Subject: [PATCH] Fixed security failure /w alignment in MemPool::Allocate(). --- libctru/source/allocator/mem_pool.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libctru/source/allocator/mem_pool.cpp b/libctru/source/allocator/mem_pool.cpp index a2c312d..13063ef 100644 --- a/libctru/source/allocator/mem_pool.cpp +++ b/libctru/source/allocator/mem_pool.cpp @@ -33,7 +33,11 @@ void MemPool::CoalesceRight(MemBlock* b) bool MemPool::Allocate(MemChunk& chunk, u32 size, int align) { int alignM = (1 << align) - 1; - size = (size + alignM) &~ alignM; // Round the size + u32 newsize; + newsize = (size + alignM) &~ alignM; // Round the size + if(newsize < size)return false;//Return error when integer-overflow occurs due to aligning the size. + size = newsize; + // Find the first suitable block for (auto b = first; b; b = b->next) {