- Get rid of GCC specific typecasts to PVOID for pointer arithmetics

- Decrement the AceCount in RtlDeleteAce instead of incrementing it

svn path=/trunk/; revision=16357
This commit is contained in:
Thomas Bluemel 2005-06-30 21:38:39 +00:00
parent 084cc36104
commit 755c848950

View file

@ -23,23 +23,25 @@ RtlFirstFreeAce(PACL Acl,
PACE* Ace) PACE* Ace)
{ {
PACE Current; PACE Current;
PVOID AclEnd; ULONG_PTR AclEnd;
ULONG i; ULONG i;
PAGED_CODE_RTL(); PAGED_CODE_RTL();
Current = (PACE)(Acl + 1); Current = (PACE)(Acl + 1);
*Ace = NULL; *Ace = NULL;
i = 0;
if (Acl->AceCount == 0) if (Acl->AceCount == 0)
{ {
*Ace = Current; *Ace = Current;
return(TRUE); return(TRUE);
} }
AclEnd = Acl->AclSize + (PVOID)Acl;
i = 0;
AclEnd = (ULONG_PTR)Acl + Acl->AclSize;
do do
{ {
if ((PVOID)Current >= AclEnd) if ((ULONG_PTR)Current >= AclEnd)
{ {
return(FALSE); return(FALSE);
} }
@ -48,12 +50,11 @@ RtlFirstFreeAce(PACL Acl,
{ {
return(FALSE); return(FALSE);
} }
Current = (PACE)((ULONG_PTR)Current + (ULONG_PTR)Current->Header.AceSize); Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
i++;
} }
while (i < Acl->AceCount); while (++i < Acl->AceCount);
if ((PVOID)Current < AclEnd) if ((ULONG_PTR)Current < AclEnd)
{ {
*Ace = Current; *Ace = Current;
} }
@ -74,29 +75,25 @@ RtlGetAce(PACL Acl,
PAGED_CODE_RTL(); PAGED_CODE_RTL();
*Ace = (PACE)(Acl + 1);
if (Acl->AclRevision < MIN_ACL_REVISION || if (Acl->AclRevision < MIN_ACL_REVISION ||
Acl->AclRevision > MAX_ACL_REVISION) Acl->AclRevision > MAX_ACL_REVISION ||
{ AceIndex >= Acl->AceCount)
return(STATUS_INVALID_PARAMETER);
}
if (AceIndex >= Acl->AceCount)
{ {
return(STATUS_INVALID_PARAMETER); return(STATUS_INVALID_PARAMETER);
} }
*Ace = (PACE)(Acl + 1);
for (i = 0; i < AceIndex; i++) 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); 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); return(STATUS_INVALID_PARAMETER);
} }
@ -244,16 +241,16 @@ RtlpAddData(PVOID AceList,
{ {
if (Offset > 0) if (Offset > 0)
{ {
memcpy((PVOID)Ace + AceListLength, RtlCopyMemory((PVOID)((ULONG_PTR)Ace + AceListLength),
Ace, Ace,
Offset); Offset);
} }
if (AceListLength != 0) if (AceListLength != 0)
{ {
memcpy(Ace, RtlCopyMemory(Ace,
AceList, AceList,
AceListLength); AceListLength);
} }
} }
@ -276,12 +273,8 @@ RtlAddAce(PACL Acl,
PAGED_CODE_RTL(); PAGED_CODE_RTL();
if (Acl->AclRevision < MIN_ACL_REVISION || 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); return(STATUS_INVALID_PARAMETER);
} }
@ -291,29 +284,25 @@ RtlAddAce(PACL Acl,
AclRevision = Acl->AclRevision; AclRevision = Acl->AclRevision;
} }
if (((PVOID)AceList + AceListLength) <= (PVOID)AceList) if (((ULONG_PTR)AceList + AceListLength) <= (ULONG_PTR)AceList)
{ {
return(STATUS_INVALID_PARAMETER); return(STATUS_INVALID_PARAMETER);
} }
i = 0; i = 0;
Current = (PACE)(Acl + 1); 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 && if (AceList->Header.AceType == ACCESS_ALLOWED_COMPOUND_ACE_TYPE &&
AclRevision < ACL_REVISION3) AclRevision < ACL_REVISION3)
{ {
return(STATUS_INVALID_PARAMETER); 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); return(STATUS_BUFFER_TOO_SMALL);
} }
@ -325,7 +314,7 @@ RtlAddAce(PACL Acl,
Current = (PACE)(Acl + 1); Current = (PACE)(Acl + 1);
for (j = 0; j < StartingIndex; j++) 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 @@ RtlAddAce(PACL Acl,
RtlpAddData(AceList, RtlpAddData(AceList,
AceListLength, AceListLength,
Current, Current,
(ULONG)Ace - (ULONG)Current); (ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
Acl->AceCount = Acl->AceCount + i; Acl->AceCount = Acl->AceCount + i;
Acl->AclRevision = AclRevision; Acl->AclRevision = AclRevision;
@ -388,12 +377,8 @@ RtlAddAuditAccessAce(PACL Acl,
return(STATUS_INVALID_ACL); 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); return(STATUS_ALLOTTED_SPACE_EXCEEDED);
} }
@ -459,12 +444,8 @@ RtlAddAuditAccessAceEx(PACL Acl,
return STATUS_INVALID_ACL; 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; return STATUS_ALLOTTED_SPACE_EXCEEDED;
} }
@ -490,16 +471,15 @@ RtlpDeleteData(PVOID Ace,
{ {
if (AceSize < Offset) if (AceSize < Offset)
{ {
memcpy(Ace, RtlCopyMemory(Ace,
(PUCHAR)Ace + AceSize, (PVOID)((ULONG_PTR)Ace + AceSize),
Offset - AceSize); Offset - AceSize);
} }
if (Offset - AceSize < Offset) if (Offset - AceSize < Offset)
{ {
memset((PUCHAR)Ace + Offset - AceSize, RtlZeroMemory((PVOID)((ULONG_PTR)Ace + Offset - AceSize),
0, AceSize);
AceSize);
} }
} }
@ -517,17 +497,9 @@ RtlDeleteAce(PACL Acl,
PAGED_CODE_RTL(); PAGED_CODE_RTL();
if (Acl->AclRevision < MIN_ACL_REVISION || if (Acl->AclRevision < MIN_ACL_REVISION ||
Acl->AclRevision > MAX_ACL_REVISION) Acl->AclRevision > MAX_ACL_REVISION ||
{ Acl->AceCount <= AceIndex ||
return(STATUS_INVALID_PARAMETER); !RtlFirstFreeAce(Acl, &Ace))
}
if (Acl->AceCount <= AceIndex)
{
return(STATUS_INVALID_PARAMETER);
}
if (!RtlFirstFreeAce(Acl, &Ace))
{ {
return(STATUS_INVALID_PARAMETER); return(STATUS_INVALID_PARAMETER);
} }
@ -536,13 +508,13 @@ RtlDeleteAce(PACL Acl,
while(AceIndex--) while(AceIndex--)
{ {
Current = (PACE)((PVOID)Current + Current->Header.AceSize); Current = (PACE)((ULONG_PTR)Current + Current->Header.AceSize);
} }
RtlpDeleteData(Current, RtlpDeleteData(Current,
Current->Header.AceSize, Current->Header.AceSize,
Ace - Current); (ULONG)((ULONG_PTR)Ace - (ULONG_PTR)Current));
Acl->AceCount++; Acl->AceCount--;
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -558,18 +530,14 @@ RtlCreateAcl(PACL Acl,
{ {
PAGED_CODE_RTL(); PAGED_CODE_RTL();
if (AclSize < 8) if (AclSize < sizeof(ACL))
{ {
return(STATUS_BUFFER_TOO_SMALL); return(STATUS_BUFFER_TOO_SMALL);
} }
if (AclRevision < MIN_ACL_REVISION || 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); return(STATUS_INVALID_PARAMETER);
} }
@ -635,7 +603,7 @@ RtlQueryInformationAcl(PACL Acl,
Info->AceCount = Acl->AceCount; Info->AceCount = Acl->AceCount;
if (Ace != NULL) if (Ace != NULL)
{ {
Info->AclBytesInUse = (PVOID)Ace - (PVOID)Acl; Info->AclBytesInUse = (DWORD)((ULONG_PTR)Ace - (ULONG_PTR)Acl);
Info->AclBytesFree = Acl->AclSize - Info->AclBytesInUse; Info->AclBytesFree = Acl->AclSize - Info->AclBytesInUse;
} }
else else