Skip to content

Commit

Permalink
provide a validity check to prevent against Integer overflow conditio…
Browse files Browse the repository at this point in the history
…ns (capstone-engine#870)

* provide a validity check to prevent against Integer overflow conditions

* fix some style issues.
  • Loading branch information
quangnh89 authored and aquynh committed Mar 13, 2017
1 parent f7a3cc2 commit 15344de
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions windows/winkernel_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "winkernel_mm.h"
#include <ntddk.h>
#include <Ntintsafe.h>

// A pool tag for memory allocation
static const ULONG CS_WINKERNEL_POOL_TAG = 'kwsC';
Expand Down Expand Up @@ -33,8 +34,16 @@ void * CAPSTONE_API cs_winkernel_malloc(size_t size)

// FP; a use of NonPagedPool is required for Windows 7 support
#pragma prefast(suppress : 30030) // Allocating executable POOL_TYPE memory
CS_WINKERNEL_MEMBLOCK *block = (CS_WINKERNEL_MEMBLOCK *)ExAllocatePoolWithTag(
NonPagedPool, size + sizeof(CS_WINKERNEL_MEMBLOCK), CS_WINKERNEL_POOL_TAG);
size_t number_of_bytes = 0;
CS_WINKERNEL_MEMBLOCK *block = NULL;
// 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 NULL.
if (!NT_SUCCESS(RtlSizeTAdd(size, sizeof(CS_WINKERNEL_MEMBLOCK), &number_of_bytes))) {
return NULL;
}
block = (CS_WINKERNEL_MEMBLOCK *)ExAllocatePoolWithTag(
NonPagedPool, number_of_bytes, CS_WINKERNEL_POOL_TAG);
if (!block) {
return NULL;
}
Expand Down

0 comments on commit 15344de

Please sign in to comment.