2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Console Server DLL
4 * FILE: win32ss/user/consrv/init.c
6 * PROGRAMMERS: Hermes Belusca-Maito (hermes.belusca@sfr.fr)
15 /* Ensure that a captured buffer is safe to access */
17 Win32CsrValidateBuffer(PCSR_PROCESS ProcessData
, PVOID Buffer
,
18 SIZE_T NumElements
, SIZE_T ElementSize
)
20 /* Check that the following conditions are true:
21 * 1. The start of the buffer is somewhere within the process's
22 * shared memory section view.
23 * 2. The remaining space in the view is at least as large as the buffer.
24 * (NB: Please don't try to "optimize" this by using multiplication
25 * instead of division; remember that 2147483648 * 2 = 0.)
26 * 3. The buffer is DWORD-aligned.
28 ULONG_PTR Offset
= (BYTE
*)Buffer
- (BYTE
*)ProcessData
->ClientViewBase
;
29 if (Offset
>= ProcessData
->ClientViewBounds
30 || NumElements
> (ProcessData
->ClientViewBounds
- Offset
) / ElementSize
31 || (Offset
& (sizeof(DWORD
) - 1)) != 0)
33 DPRINT1("Invalid buffer %p(%u*%u); section view is %p(%u)\n",
34 Buffer
, NumElements
, ElementSize
,
35 ProcessData
->ClientViewBase
, ProcessData
->ClientViewBounds
);