- 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.
Modified: trunk/reactos/ntoskrnl/cm/regobj.c

Modified: trunk/reactos/ntoskrnl/cm/regobj.c
--- trunk/reactos/ntoskrnl/cm/regobj.c	2005-09-24 18:09:06 UTC (rev 18029)
+++ trunk/reactos/ntoskrnl/cm/regobj.c	2005-09-24 18:28:04 UTC (rev 18030)
@@ -490,50 +490,50 @@
 		    ULONG Length,
 		    PULONG ReturnLength)
 {
-  POBJECT_NAME_INFORMATION LocalInfo;
   PKEY_OBJECT KeyObject;
-  ULONG LocalReturnLength;
   NTSTATUS Status;
 
   DPRINT ("CmiObjectQueryName() called\n");
 
   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)
     {
       Status = ObQueryNameString (KeyObject->ParentKey,
-				  LocalInfo,
-				  MAX_PATH * sizeof(WCHAR),
-				  &LocalReturnLength);
+				  ObjectNameInfo,
+				  Length,
+				  ReturnLength);
     }
   else
     {
       /* KeyObject is the root key */
       Status = ObQueryNameString (HEADER_TO_OBJECT_NAME(BODY_TO_HEADER(KeyObject))->Directory,
-				  LocalInfo,
-				  MAX_PATH * sizeof(WCHAR),
-				  &LocalReturnLength);
+				  ObjectNameInfo,
+				  Length,
+				  ReturnLength);
     }
 
-  if (!NT_SUCCESS (Status))
+  if (!NT_SUCCESS(Status) && Status != STATUS_INFO_LENGTH_MISMATCH)
     {
-      ExFreePool (LocalInfo);
       return Status;
     }
-  DPRINT ("Parent path: %wZ\n", &LocalInfo->Name);
+  (*ReturnLength) += sizeof(WCHAR) + KeyObject->Name.Length;
 
-  Status = RtlAppendUnicodeStringToString (&ObjectNameInfo->Name,
-					   &LocalInfo->Name);
-  ExFreePool (LocalInfo);
-  if (!NT_SUCCESS (Status))
-    return Status;
+  if (Status == STATUS_INFO_LENGTH_MISMATCH || *ReturnLength > Length)
+    {
+      return STATUS_INFO_LENGTH_MISMATCH;
+    }
 
+  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,
 				     L"\\");
   if (!NT_SUCCESS (Status))