mirror of
https://github.com/capstone-engine/capstone
synced 2026-08-11 16:26:07 -04:00
Fix an integer overflow issue (#871)
* provide a validity check to prevent against Integer overflow conditions * fix some style issues. * provide a validity check in malloc() function to prevent against integer overflow conditions * missing Ntintsafe.h * use tabs for indentation
This commit is contained in:
parent
5be7444c09
commit
85f4b8f7d9
1 changed files with 9 additions and 1 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "libc.h"
|
||||
#include <memory>
|
||||
#include <Ntintsafe.h>
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning (disable : 4565)
|
||||
|
|
@ -33,10 +34,17 @@ __cdecl malloc(
|
|||
__in size_t size
|
||||
)
|
||||
{
|
||||
/* A specially crafted size value can trigger the overflow.
|
||||
If the sum in a value that overflows or underflows the capacity of the type,
|
||||
the function returns nullptr. */
|
||||
size_t number_of_bytes = 0;
|
||||
if (!NT_SUCCESS(RtlSizeTAdd(size, sizeof(MEMBLOCK), &number_of_bytes))){
|
||||
return nullptr;
|
||||
}
|
||||
MEMBLOCK *pBlock = static_cast<MEMBLOCK*>(
|
||||
ExAllocatePoolWithTag(
|
||||
NonPagedPoolNxCacheAligned,
|
||||
size + sizeof(MEMBLOCK),
|
||||
number_of_bytes,
|
||||
_LIBC_POOL_TAG));
|
||||
|
||||
if (nullptr == pBlock)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue