File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 3
3
4
4
#include "winkernel_mm.h"
5
5
#include <ntddk.h>
6
+ #include <Ntintsafe.h>
6
7
7
8
// A pool tag for memory allocation
8
9
static const ULONG CS_WINKERNEL_POOL_TAG = 'kwsC' ;
@@ -33,8 +34,16 @@ void * CAPSTONE_API cs_winkernel_malloc(size_t size)
33
34
34
35
// FP; a use of NonPagedPool is required for Windows 7 support
35
36
#pragma prefast(suppress : 30030) // Allocating executable POOL_TYPE memory
36
- CS_WINKERNEL_MEMBLOCK * block = (CS_WINKERNEL_MEMBLOCK * )ExAllocatePoolWithTag (
37
- NonPagedPool , size + sizeof (CS_WINKERNEL_MEMBLOCK ), CS_WINKERNEL_POOL_TAG );
37
+ size_t number_of_bytes = 0 ;
38
+ CS_WINKERNEL_MEMBLOCK * block = NULL ;
39
+ // A specially crafted size value can trigger the overflow.
40
+ // If the sum in a value that overflows or underflows the capacity of the type,
41
+ // the function returns NULL.
42
+ if (!NT_SUCCESS (RtlSizeTAdd (size , sizeof (CS_WINKERNEL_MEMBLOCK ), & number_of_bytes ))) {
43
+ return NULL ;
44
+ }
45
+ block = (CS_WINKERNEL_MEMBLOCK * )ExAllocatePoolWithTag (
46
+ NonPagedPool , number_of_bytes , CS_WINKERNEL_POOL_TAG );
38
47
if (!block ) {
39
48
return NULL ;
40
49
}
You can’t perform that action at this time.
0 commit comments