don't touch memory outside the area to be probed in ProbeForWrite() and minor address range check fixes in ProbeForRead/Write()

svn path=/trunk/; revision=13167
This commit is contained in:
Thomas Bluemel 2005-01-20 21:03:35 +00:00
parent 0b7bbeea36
commit 808fec3b76

View file

@ -795,7 +795,7 @@ ProbeForRead (IN CONST VOID *Address,
IN ULONG Length, IN ULONG Length,
IN ULONG Alignment) IN ULONG Alignment)
{ {
ASSERT(Alignment ==1 || Alignment == 2 || Alignment == 4 || Alignment == 8); ASSERT(Alignment == 1 || Alignment == 2 || Alignment == 4 || Alignment == 8);
if (Length == 0) if (Length == 0)
return; return;
@ -804,8 +804,8 @@ ProbeForRead (IN CONST VOID *Address,
{ {
ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT); ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT);
} }
else if ((ULONG_PTR)Address + Length < (ULONG_PTR)Address || else if ((ULONG_PTR)Address + Length - 1 < (ULONG_PTR)Address ||
(ULONG_PTR)Address + Length > (ULONG_PTR)MmUserProbeAddress) (ULONG_PTR)Address + Length - 1 > (ULONG_PTR)MmUserProbeAddress)
{ {
ExRaiseStatus (STATUS_ACCESS_VIOLATION); ExRaiseStatus (STATUS_ACCESS_VIOLATION);
} }
@ -820,10 +820,10 @@ ProbeForWrite (IN CONST VOID *Address,
IN ULONG Length, IN ULONG Length,
IN ULONG Alignment) IN ULONG Alignment)
{ {
volatile PCHAR Ptr; volatile CHAR *Current;
ULONG i; PCHAR Last;
ASSERT(Alignment ==1 || Alignment == 2 || Alignment == 4 || Alignment == 8); ASSERT(Alignment == 1 || Alignment == 2 || Alignment == 4 || Alignment == 8);
if (Length == 0) if (Length == 0)
return; return;
@ -832,18 +832,21 @@ ProbeForWrite (IN CONST VOID *Address,
{ {
ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT); ExRaiseStatus (STATUS_DATATYPE_MISALIGNMENT);
} }
else if ((ULONG_PTR)Address + Length < (ULONG_PTR)Address ||
(ULONG_PTR)Address + Length > (ULONG_PTR)MmUserProbeAddress) Last = (PCHAR)((ULONG_PTR)Address + Length - 1);
if ((ULONG_PTR)Last < (ULONG_PTR)Address ||
(ULONG_PTR)Last > (ULONG_PTR)MmUserProbeAddress)
{ {
ExRaiseStatus (STATUS_ACCESS_VIOLATION); ExRaiseStatus (STATUS_ACCESS_VIOLATION);
} }
/* Check for accessible pages */ /* Check for accessible pages */
for (i = 0; i < Length; i += PAGE_SIZE) Current = (CHAR*)Address;
do
{ {
Ptr = (PCHAR)(((ULONG_PTR)Address & ~(PAGE_SIZE - 1)) + i); *Current = *Current;
*Ptr = *Ptr; Current = (CHAR*)((ULONG_PTR)Current + PAGE_SIZE);
} } while (Current <= Last);
} }
/* EOF */ /* EOF */