- Use the given buffer for getting the name of the parent.

- Check the length of the buffer.  
- Intialise the name string if it is necessary.

svn path=/trunk/; revision=18030
This commit is contained in:
Hartmut Birr 2005-09-24 18:28:04 +00:00
parent 2914b8925b
commit 262c303ffb

View file

@ -490,49 +490,49 @@ CmiObjectQueryName (PVOID ObjectBody,
ULONG Length, ULONG Length,
PULONG ReturnLength) PULONG ReturnLength)
{ {
POBJECT_NAME_INFORMATION LocalInfo;
PKEY_OBJECT KeyObject; PKEY_OBJECT KeyObject;
ULONG LocalReturnLength;
NTSTATUS Status; NTSTATUS Status;
DPRINT ("CmiObjectQueryName() called\n"); DPRINT ("CmiObjectQueryName() called\n");
KeyObject = (PKEY_OBJECT)ObjectBody; KeyObject = (PKEY_OBJECT)ObjectBody;
LocalInfo = ExAllocatePool (NonPagedPool,
sizeof(OBJECT_NAME_INFORMATION) +
MAX_PATH * sizeof(WCHAR));
if (LocalInfo == NULL)
return STATUS_INSUFFICIENT_RESOURCES;
if (KeyObject->ParentKey != KeyObject) if (KeyObject->ParentKey != KeyObject)
{ {
Status = ObQueryNameString (KeyObject->ParentKey, Status = ObQueryNameString (KeyObject->ParentKey,
LocalInfo, ObjectNameInfo,
MAX_PATH * sizeof(WCHAR), Length,
&LocalReturnLength); ReturnLength);
} }
else else
{ {
/* KeyObject is the root key */ /* KeyObject is the root key */
Status = ObQueryNameString (HEADER_TO_OBJECT_NAME(BODY_TO_HEADER(KeyObject))->Directory, Status = ObQueryNameString (HEADER_TO_OBJECT_NAME(BODY_TO_HEADER(KeyObject))->Directory,
LocalInfo, ObjectNameInfo,
MAX_PATH * sizeof(WCHAR), Length,
&LocalReturnLength); ReturnLength);
} }
if (!NT_SUCCESS (Status)) if (!NT_SUCCESS(Status) && Status != STATUS_INFO_LENGTH_MISMATCH)
{ {
ExFreePool (LocalInfo);
return Status; return Status;
} }
DPRINT ("Parent path: %wZ\n", &LocalInfo->Name); (*ReturnLength) += sizeof(WCHAR) + KeyObject->Name.Length;
Status = RtlAppendUnicodeStringToString (&ObjectNameInfo->Name, if (Status == STATUS_INFO_LENGTH_MISMATCH || *ReturnLength > Length)
&LocalInfo->Name); {
ExFreePool (LocalInfo); return STATUS_INFO_LENGTH_MISMATCH;
if (!NT_SUCCESS (Status)) }
return Status;
if (ObjectNameInfo->Name.Buffer == NULL)
{
ObjectNameInfo->Name.Buffer = (PWCHAR)(ObjectNameInfo + 1);
ObjectNameInfo->Name.Length = 0;
ObjectNameInfo->Name.MaximumLength = Length - sizeof(OBJECT_NAME_INFORMATION);
}
DPRINT ("Parent path: %wZ\n", ObjectNameInfo->Name);
Status = RtlAppendUnicodeToString (&ObjectNameInfo->Name, Status = RtlAppendUnicodeToString (&ObjectNameInfo->Name,
L"\\"); L"\\");