fixed ObpCaptureObjectAttributes()

svn path=/trunk/; revision=13486
This commit is contained in:
Thomas Bluemel 2005-02-10 11:32:06 +00:00
parent f49c77e03f
commit ca15298d31
2 changed files with 67 additions and 53 deletions

View file

@ -117,7 +117,7 @@ NtCreateEventPair(OUT PHANDLE EventPairHandle,
} }
} }
Status = ObCreateObject(ExGetPreviousMode(), Status = ObCreateObject(PreviousMode,
ExEventPairObjectType, ExEventPairObjectType,
ObjectAttributes, ObjectAttributes,
PreviousMode, PreviousMode,

View file

@ -47,24 +47,16 @@ ObpCaptureObjectAttributes(IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
{ {
OBJECT_ATTRIBUTES AttributesCopy; OBJECT_ATTRIBUTES AttributesCopy;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
/* at least one output parameter must be != NULL! */ /* at least one output parameter must be != NULL! */
ASSERT(((ULONG_PTR)CapturedObjectAttributes ^ (ULONG_PTR)ObjectName) != 0); ASSERT(CapturedObjectAttributes != NULL || ObjectName != NULL);
if(ObjectAttributes == NULL) if(ObjectAttributes == NULL)
{ {
failbasiccleanup: /* we're going to return STATUS_SUCCESS! */
if(ObjectName != NULL) goto failbasiccleanup;
{
RtlInitUnicodeString(ObjectName, NULL);
}
if(CapturedObjectAttributes != NULL)
{
RtlZeroMemory(CapturedObjectAttributes, sizeof(CAPTURED_OBJECT_ATTRIBUTES));
}
return Status; /* STATUS_SUCCESS */
} }
if(AccessMode != KernelMode) if(AccessMode != KernelMode)
{ {
_SEH_TRY _SEH_TRY
@ -80,21 +72,30 @@ failbasiccleanup:
Status = _SEH_GetExceptionCode(); Status = _SEH_GetExceptionCode();
} }
_SEH_END; _SEH_END;
if(!NT_SUCCESS(Status)) if(!NT_SUCCESS(Status))
{ {
return Status; DPRINT1("ObpCaptureObjectAttributes failed to probe object attributes\n");
goto failbasiccleanup;
} }
} }
else if(AccessMode == KernelMode && !CaptureIfKernel) else if(!CaptureIfKernel)
{ {
if(ObjectAttributes->Length != sizeof(OBJECT_ATTRIBUTES)) if(ObjectAttributes->Length == sizeof(OBJECT_ATTRIBUTES))
{ {
/* we don't have to capture any memory, the caller considers the passed data
as valid */
if(ObjectName != NULL) if(ObjectName != NULL)
{ {
*ObjectName = *ObjectAttributes->ObjectName; /* we don't have to capture any memory, the caller considers the passed data
as valid */
if(ObjectAttributes->ObjectName != NULL)
{
*ObjectName = *ObjectAttributes->ObjectName;
}
else
{
ObjectName->Length = ObjectName->MaximumLength = 0;
ObjectName->Buffer = NULL;
}
} }
if(CapturedObjectAttributes != NULL) if(CapturedObjectAttributes != NULL)
{ {
@ -115,7 +116,7 @@ failbasiccleanup:
{ {
AttributesCopy = *ObjectAttributes; AttributesCopy = *ObjectAttributes;
} }
/* if Length isn't as expected, bail with an invalid parameter status code so /* if Length isn't as expected, bail with an invalid parameter status code so
the caller knows he passed garbage... */ the caller knows he passed garbage... */
if(AttributesCopy.Length != sizeof(OBJECT_ATTRIBUTES)) if(AttributesCopy.Length != sizeof(OBJECT_ATTRIBUTES))
@ -123,7 +124,7 @@ failbasiccleanup:
Status = STATUS_INVALID_PARAMETER; Status = STATUS_INVALID_PARAMETER;
goto failbasiccleanup; goto failbasiccleanup;
} }
if(CapturedObjectAttributes != NULL) if(CapturedObjectAttributes != NULL)
{ {
CapturedObjectAttributes->RootDirectory = AttributesCopy.RootDirectory; CapturedObjectAttributes->RootDirectory = AttributesCopy.RootDirectory;
@ -147,13 +148,13 @@ failbasiccleanup:
CapturedObjectAttributes->SecurityDescriptor = NULL; CapturedObjectAttributes->SecurityDescriptor = NULL;
} }
} }
if(ObjectName != NULL) if(ObjectName != NULL)
{ {
if(AttributesCopy.ObjectName != NULL) if(AttributesCopy.ObjectName != NULL)
{ {
UNICODE_STRING OriginalCopy; UNICODE_STRING OriginalCopy;
if(AccessMode != KernelMode) if(AccessMode != KernelMode)
{ {
_SEH_TRY _SEH_TRY
@ -175,7 +176,7 @@ failbasiccleanup:
Status = _SEH_GetExceptionCode(); Status = _SEH_GetExceptionCode();
} }
_SEH_END; _SEH_END;
if(NT_SUCCESS(Status)) if(NT_SUCCESS(Status))
{ {
if(OriginalCopy.Length > 0) if(OriginalCopy.Length > 0)
@ -197,6 +198,11 @@ failbasiccleanup:
Status = _SEH_GetExceptionCode(); Status = _SEH_GetExceptionCode();
} }
_SEH_END; _SEH_END;
if(!NT_SUCCESS(Status))
{
DPRINT1("ObpCaptureObjectAttributes failed to copy the unicode string!\n");
}
} }
else else
{ {
@ -209,29 +215,15 @@ failbasiccleanup:
Status = STATUS_OBJECT_NAME_INVALID; Status = STATUS_OBJECT_NAME_INVALID;
} }
} }
else
/* handle failure */
if(!NT_SUCCESS(Status))
{ {
failallocatedcleanup: DPRINT1("ObpCaptureObjectAttributes failed to probe the object name UNICODE_STRING structure!\n");
if(ObjectName->Buffer)
{
ExFreePool(ObjectName->Buffer);
}
if(CapturedObjectAttributes != NULL)
{
/* cleanup allocated resources */
SeReleaseSecurityDescriptor(CapturedObjectAttributes->SecurityDescriptor,
AccessMode,
TRUE);
}
goto failbasiccleanup;
} }
} }
else /* AccessMode == KernelMode */ else /* AccessMode == KernelMode */
{ {
OriginalCopy = *AttributesCopy.ObjectName; OriginalCopy = *AttributesCopy.ObjectName;
if(OriginalCopy.Length > 0) if(OriginalCopy.Length > 0)
{ {
ObjectName->MaximumLength = OriginalCopy.Length + sizeof(WCHAR); ObjectName->MaximumLength = OriginalCopy.Length + sizeof(WCHAR);
@ -252,22 +244,45 @@ failallocatedcleanup:
/* if the caller specified a root directory, there must be an object name! */ /* if the caller specified a root directory, there must be an object name! */
Status = STATUS_OBJECT_NAME_INVALID; Status = STATUS_OBJECT_NAME_INVALID;
} }
if(!NT_SUCCESS(Status))
{
goto failallocatedcleanup;
}
} }
} }
else else
{ {
RtlInitUnicodeString(ObjectName, NULL); ObjectName->Length = ObjectName->MaximumLength = 0;
ObjectName->Buffer = NULL;
} }
} }
if(!NT_SUCCESS(Status))
{
if(ObjectName->Buffer)
{
ExFreePool(ObjectName->Buffer);
}
if(CapturedObjectAttributes != NULL)
{
/* cleanup allocated resources */
SeReleaseSecurityDescriptor(CapturedObjectAttributes->SecurityDescriptor,
AccessMode,
TRUE);
}
failbasiccleanup:
if(ObjectName != NULL)
{
ObjectName->Length = ObjectName->MaximumLength = 0;
ObjectName->Buffer = NULL;
}
if(CapturedObjectAttributes != NULL)
{
RtlZeroMemory(CapturedObjectAttributes, sizeof(CAPTURED_OBJECT_ATTRIBUTES));
}
}
return Status; return Status;
} }
VOID VOID
ObpReleaseObjectAttributes(IN PCAPTURED_OBJECT_ATTRIBUTES CapturedObjectAttributes OPTIONAL, ObpReleaseObjectAttributes(IN PCAPTURED_OBJECT_ATTRIBUTES CapturedObjectAttributes OPTIONAL,
IN PUNICODE_STRING ObjectName OPTIONAL, IN PUNICODE_STRING ObjectName OPTIONAL,
@ -276,8 +291,7 @@ ObpReleaseObjectAttributes(IN PCAPTURED_OBJECT_ATTRIBUTES CapturedObjectAttribut
{ {
/* WARNING - You need to pass the same parameters to this function as you passed /* WARNING - You need to pass the same parameters to this function as you passed
to ObpCaptureObjectAttributes() to avoid memory leaks */ to ObpCaptureObjectAttributes() to avoid memory leaks */
if(AccessMode != KernelMode || if(AccessMode != KernelMode || CaptureIfKernel)
(AccessMode == KernelMode && CaptureIfKernel))
{ {
if(CapturedObjectAttributes != NULL && if(CapturedObjectAttributes != NULL &&
CapturedObjectAttributes->SecurityDescriptor != NULL) CapturedObjectAttributes->SecurityDescriptor != NULL)