--- trunk/reactos/lib/rtl/acl.c 2005-06-30 17:00:19 UTC (rev 16356)
+++ trunk/reactos/lib/rtl/acl.c 2005-06-30 21:38:39 UTC (rev 16357)
@@ -23,23 +23,25 @@
PACE* Ace)
{
PACE Current;
- PVOID AclEnd;
+ ULONG_PTR AclEnd;
ULONG i;
PAGED_CODE_RTL();
Current = (PACE)(Acl + 1);
*Ace = NULL;
- i = 0;
+
if (Acl->AceCount == 0)
{
*Ace = Current;
return(TRUE);
}
- AclEnd = Acl->AclSize + (PVOID)Acl;
+
+ i = 0;
+ AclEnd = (ULONG_PTR)Acl + Acl->AclSize;
do
{
- if ((PVOID)Current >= AclEnd)
+ if ((ULONG_PTR)Current >= AclEnd)
{
return(FALSE);
}
@@ -48,12 +50,11 @@
{
return(FALSE);
}
- Current = (PACE)((ULONG_PTR)Current + (ULONG_PTR)Current->Header.AceSize);
- i++;
+ Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
}
- while (i < Acl->AceCount);
+ while (++i < Acl->AceCount);
- if ((PVOID)Current < AclEnd)
+ if ((ULONG_PTR)Current < AclEnd)
{
*Ace = Current;
}
@@ -74,29 +75,25 @@
PAGED_CODE_RTL();
- *Ace = (PACE)(Acl + 1);
-
if (Acl->AclRevision < MIN_ACL_REVISION ||
- Acl->AclRevision > MAX_ACL_REVISION)
+ Acl->AclRevision > MAX_ACL_REVISION ||
+ AceIndex >= Acl->AceCount)
{
return(STATUS_INVALID_PARAMETER);
}
+
+ *Ace = (PACE)(Acl + 1);
- if (AceIndex >= Acl->AceCount)
- {
- return(STATUS_INVALID_PARAMETER);
- }
-
for (i = 0; i < AceIndex; i++)
{
- if ((PVOID)*Ace >= (PVOID)Acl + Acl->AclSize)
+ if ((ULONG_PTR)*Ace >= (ULONG_PTR)Acl + Acl->AclSize)
{
return(STATUS_INVALID_PARAMETER);
}
- *Ace = (PACE)((PVOID)(*Ace) + (ULONG)(*Ace)->Header.AceSize);
+ *Ace = (PACE)((ULONG_PTR)(*Ace) + (*Ace)->Header.AceSize);
}
- if ((PVOID)*Ace >= (PVOID)Acl + Acl->AclSize)
+ if ((ULONG_PTR)*Ace >= (ULONG_PTR)Acl + Acl->AclSize)
{
return(STATUS_INVALID_PARAMETER);
}
@@ -244,16 +241,16 @@
{
if (Offset > 0)
{
- memcpy((PVOID)Ace + AceListLength,
- Ace,
- Offset);
+ RtlCopyMemory((PVOID)((ULONG_PTR)Ace + AceListLength),
+ Ace,
+ Offset);
}
if (AceListLength != 0)
{
- memcpy(Ace,
- AceList,
- AceListLength);
+ RtlCopyMemory(Ace,
+ AceList,
+ AceListLength);
}
}
@@ -276,48 +273,40 @@
PAGED_CODE_RTL();
if (Acl->AclRevision < MIN_ACL_REVISION ||
- Acl->AclRevision > MAX_ACL_REVISION)
+ Acl->AclRevision > MAX_ACL_REVISION ||
+ !RtlFirstFreeAce(Acl, &Ace))
{
return(STATUS_INVALID_PARAMETER);
}
- if (!RtlFirstFreeAce(Acl,&Ace))
- {
- return(STATUS_INVALID_PARAMETER);
- }
-
if (Acl->AclRevision <= AclRevision)
{
AclRevision = Acl->AclRevision;
}
- if (((PVOID)AceList + AceListLength) <= (PVOID)AceList)
+ if (((ULONG_PTR)AceList + AceListLength) <= (ULONG_PTR)AceList)
{
return(STATUS_INVALID_PARAMETER);
}
i = 0;
Current = (PACE)(Acl + 1);
- while ((PVOID)Current < ((PVOID)AceList + AceListLength))
+ while ((ULONG_PTR)Current < ((ULONG_PTR)AceList + AceListLength))
{
if (AceList->Header.AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE &&
AclRevision < ACL_REVISION3)
{
return(STATUS_INVALID_PARAMETER);
}
- Current = (PACE)((PVOID)Current + Current->Header.AceSize);
+ Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
}
- if (Ace == NULL)
+ if (Ace == NULL ||
+ ((ULONG_PTR)Ace + AceListLength) >= ((ULONG_PTR)Acl + Acl->AclSize))
{
return(STATUS_BUFFER_TOO_SMALL);
}
- if (((PVOID)Ace + AceListLength) >= ((PVOID)Acl + Acl->AclSize))
- {
- return(STATUS_BUFFER_TOO_SMALL);
- }
-
if (StartingIndex != 0)
{
if (Acl->AceCount > 0)
@@ -325,7 +314,7 @@
Current = (PACE)(Acl + 1);
for (j = 0; j < StartingIndex; j++)
{
- Current = (PACE)((PVOID)Current + Current->Header.AceSize);
+ Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
}
}
}
@@ -333,7 +322,7 @@
RtlpAddData(AceList,
AceListLength,
Current,
- (ULONG)Ace - (ULONG)Current);
+ (ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
Acl->AceCount = Acl->AceCount + i;
Acl->AclRevision = AclRevision;
@@ -388,16 +377,12 @@
return(STATUS_INVALID_ACL);
}
- if (Ace == NULL)
+ if (Ace == NULL ||
+ ((ULONG_PTR)Ace + RtlLengthSid(Sid) + sizeof(ACE)) > ((ULONG_PTR)Acl + Acl->AclSize))
{
return(STATUS_ALLOTTED_SPACE_EXCEEDED);
}
- if (((PVOID)Ace + RtlLengthSid(Sid) + sizeof(ACE)) >= ((PVOID)Acl + Acl->AclSize))
- {
- return(STATUS_ALLOTTED_SPACE_EXCEEDED);
- }
-
Ace->Header.AceFlags = Flags;
Ace->Header.AceType = SYSTEM_AUDIT_ACE_TYPE;
Ace->Header.AceSize = RtlLengthSid(Sid) + sizeof(ACE);
@@ -459,16 +444,12 @@
return STATUS_INVALID_ACL;
}
- if (Ace == NULL)
+ if (Ace == NULL ||
+ ((ULONG_PTR)Ace + RtlLengthSid(Sid) + sizeof(ACE)) >= ((ULONG_PTR)Acl + Acl->AclSize))
{
return STATUS_ALLOTTED_SPACE_EXCEEDED;
}
- if (((PVOID)Ace + RtlLengthSid(Sid) + sizeof(ACE)) >= ((PVOID)Acl + Acl->AclSize))
- {
- return STATUS_ALLOTTED_SPACE_EXCEEDED;
- }
-
Ace->Header.AceFlags = Flags;
Ace->Header.AceType = SYSTEM_AUDIT_ACE_TYPE;
Ace->Header.AceSize = RtlLengthSid(Sid) + sizeof(ACE);
@@ -490,16 +471,15 @@
{
if (AceSize < Offset)
{
- memcpy(Ace,
- (PUCHAR)Ace + AceSize,
- Offset - AceSize);
+ RtlCopyMemory(Ace,
+ (PVOID)((ULONG_PTR)Ace + AceSize),
+ Offset - AceSize);
}
if (Offset - AceSize < Offset)
{
- memset((PUCHAR)Ace + Offset - AceSize,
- 0,
- AceSize);
+ RtlZeroMemory((PVOID)((ULONG_PTR)Ace + Offset - AceSize),
+ AceSize);
}
}
@@ -517,32 +497,24 @@
PAGED_CODE_RTL();
if (Acl->AclRevision < MIN_ACL_REVISION ||
- Acl->AclRevision > MAX_ACL_REVISION)
+ Acl->AclRevision > MAX_ACL_REVISION ||
+ Acl->AceCount <= AceIndex ||
+ !RtlFirstFreeAce(Acl, &Ace))
{
return(STATUS_INVALID_PARAMETER);
}
- if (Acl->AceCount <= AceIndex)
- {
- return(STATUS_INVALID_PARAMETER);
- }
-
- if (!RtlFirstFreeAce(Acl, &Ace))
- {
- return(STATUS_INVALID_PARAMETER);
- }
-
Current = (PACE)(Acl + 1);
while(AceIndex--)
{
- Current = (PACE)((PVOID)Current + Current->Header.AceSize);
+ Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
}
RtlpDeleteData(Current,
Current->Header.AceSize,
- Ace - Current);
- Acl->AceCount++;
+ (ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
+ Acl->AceCount--;
return(STATUS_SUCCESS);
}
@@ -558,22 +530,18 @@
{
PAGED_CODE_RTL();
- if (AclSize < 8)
+ if (AclSize < sizeof(ACL))
{
return(STATUS_BUFFER_TOO_SMALL);
}
if (AclRevision < MIN_ACL_REVISION ||
- AclRevision > MAX_ACL_REVISION)
+ AclRevision > MAX_ACL_REVISION ||
+ AclSize > 0xffff)
{
return(STATUS_INVALID_PARAMETER);
}
- if (AclSize > 0xffff)
- {
- return(STATUS_INVALID_PARAMETER);
- }
-
AclSize = ROUND_UP(AclSize, 4);
Acl->AclSize = AclSize;
Acl->AclRevision = AclRevision;
@@ -635,7 +603,7 @@
Info->AceCount = Acl->AceCount;
if (Ace != NULL)
{
- Info->AclBytesInUse = (PVOID)Ace - (PVOID)Acl;
+ Info->AclBytesInUse = (DWORD)((ULONG_PTR)Ace - (ULONG_PTR)Acl);
Info->AclBytesFree = Acl->AclSize - Info->AclBytesInUse;
}
else