Commit in reactos/ntoskrnl/cm on MAIN
ntfunc.c+17-61.63 -> 1.64
regfile.c+78-541.71 -> 1.72
registry.c+32-301.122 -> 1.123
+127-90
3 modified files
Fix key name size calculation bugs.
Fill some allocated buffers with zeros.
Minor cleanup.

reactos/ntoskrnl/cm
ntfunc.c 1.63 -> 1.64
diff -u -r1.63 -r1.64
--- ntfunc.c	28 Feb 2004 15:12:37 -0000	1.63
+++ ntfunc.c	13 Mar 2004 12:14:44 -0000	1.64
@@ -404,7 +404,7 @@
       KeLeaveCriticalRegion();
       ObDereferenceObject(KeyObject);
       DPRINT("No more entries\n");
-      return(STATUS_NO_MORE_ENTRIES);
+      return STATUS_NO_MORE_ENTRIES;
     }
 
   Status = STATUS_SUCCESS;
@@ -412,10 +412,17 @@
     {
       case KeyBasicInformation:
 	/* Check size of buffer */
-	NameSize = SubKeyCell->NameSize;
-	if (SubKeyCell->Flags & REG_KEY_NAME_PACKED)
+	if (SubKeyObject != NULL)
 	  {
-	    NameSize *= sizeof(WCHAR);
+	    NameSize = SubKeyObject->Name.Length;
+	  }
+	else
+	  {
+	    NameSize = SubKeyCell->NameSize;
+	    if (SubKeyCell->Flags & REG_KEY_NAME_PACKED)
+	      {
+		NameSize *= sizeof(WCHAR);
+	      }
 	  }
 	*ResultLength = sizeof(KEY_BASIC_INFORMATION) + NameSize;
 
@@ -460,13 +467,17 @@
 
       case KeyNodeInformation:
 	/* Check size of buffer */
-	if (SubKeyCell->Flags & REG_KEY_NAME_PACKED)
+	if (SubKeyObject != NULL)
 	  {
-	    NameSize = SubKeyCell->NameSize * sizeof(WCHAR);
+	    NameSize = SubKeyObject->Name.Length;
 	  }
 	else
 	  {
 	    NameSize = SubKeyCell->NameSize;
+	    if (SubKeyCell->Flags & REG_KEY_NAME_PACKED)
+	      {
+		NameSize *= sizeof(WCHAR);
+	      }
 	  }
 	*ResultLength = sizeof(KEY_NODE_INFORMATION) +
 	  NameSize + SubKeyCell->ClassSize;

reactos/ntoskrnl/cm
regfile.c 1.71 -> 1.72
diff -u -r1.71 -r1.72
--- regfile.c	31 Jan 2004 14:33:01 -0000	1.71
+++ regfile.c	13 Mar 2004 12:14:44 -0000	1.72
@@ -369,6 +369,9 @@
   if (Buffer == NULL)
     return STATUS_INSUFFICIENT_RESOURCES;
 
+  RtlZeroMemory (Buffer,
+		 2 * REG_BLOCK_SIZE);
+
   HiveHeader = (PHIVE_HEADER)Buffer;
   BinCell = (PHBIN)((ULONG_PTR)Buffer + REG_BLOCK_SIZE);
   RootKeyCell = (PKEY_CELL)((ULONG_PTR)Buffer + REG_BLOCK_SIZE + REG_HBIN_DATA_OFFSET);
@@ -985,7 +988,7 @@
 
   /* Allocate hive block list */
   RegistryHive->BlockList = ExAllocatePool(NonPagedPool,
-	  sizeof(PHBIN *) * RegistryHive->BlockListSize);
+					   sizeof(PHBIN *) * RegistryHive->BlockListSize);
   if (RegistryHive->BlockList == NULL)
     {
       DPRINT1("Failed to allocate the hive block list\n");
@@ -996,6 +999,8 @@
       RtlFreeUnicodeString(&RegistryHive->LogFileName);
       return STATUS_INSUFFICIENT_RESOURCES;
     }
+  RtlZeroMemory (RegistryHive->BlockList,
+		 RegistryHive->BlockListSize * sizeof(PHBIN *));
 
   /* Import the hive bins */
   Status = CmiImportHiveBins (RegistryHive,
@@ -1042,7 +1047,7 @@
   DPRINT("CmiInitNonVolatileRegistryHive(%p, %S) - Finished.\n",
 	 RegistryHive, Filename);
 
-  return(STATUS_SUCCESS);
+  return STATUS_SUCCESS;
 }
 
 
@@ -1071,6 +1076,8 @@
       ExFreePool (Hive);
       return STATUS_INSUFFICIENT_RESOURCES;
     }
+  RtlZeroMemory (Hive->HiveHeader,
+		 sizeof(HIVE_HEADER));
 
   Hive->Flags = (HIVE_NO_FILE | HIVE_POINTER);
 
@@ -1270,6 +1277,9 @@
       return STATUS_INSUFFICIENT_RESOURCES;
     }
 
+  RtlZeroMemory (Hive->HiveHeader,
+		 sizeof(HIVE_HEADER));
+
   Status = CmiInitNonVolatileRegistryHive (Hive,
 					   FileName->Buffer);
   if (!NT_SUCCESS (Status))
@@ -1395,12 +1405,15 @@
 
   DPRINT("Bitmap size %lu  buffer size: %lu\n", BitmapSize, BufferSize);
 
-  Buffer = (PUCHAR)ExAllocatePool(NonPagedPool, BufferSize);
+  Buffer = (PUCHAR)ExAllocatePool(NonPagedPool,
+				  BufferSize);
   if (Buffer == NULL)
     {
       DPRINT("ExAllocatePool() failed\n");
       return(STATUS_INSUFFICIENT_RESOURCES);
     }
+  RtlZeroMemory (Buffer,
+		 BufferSize);
 
   /* Open log file for writing */
   InitializeObjectAttributes(&ObjectAttributes,
@@ -2094,12 +2107,14 @@
 	          DPRINT("CmiGetBlock() failed\n");
 	          continue;
 	        }
+
 	      NameSize = CurSubKeyCell->NameSize;
 	      if (CurSubKeyCell->Flags & REG_KEY_NAME_PACKED)
 	        {
 	          NameSize *= sizeof(WCHAR);
 	        }
-	      if (MaxName < NameSize)
+
+	      if (NameSize > MaxName)
 	        {
 	          MaxName = NameSize;
 	        }
@@ -2107,7 +2122,7 @@
 	}
     }
 
-  DPRINT("KeyObject->NumberOfSubKeys %d\n", KeyObject->NumberOfSubKeys);
+  DPRINT ("KeyObject->NumberOfSubKeys %d\n", KeyObject->NumberOfSubKeys);
   for (i = 0; i < KeyObject->NumberOfSubKeys; i++)
     {
       CurKey = KeyObject->SubKeys[i];
@@ -2121,19 +2136,31 @@
 	      continue;
 	    }
 
-	  NameSize = CurSubKeyCell->NameSize;
-	  if (CurSubKeyCell->Flags & REG_KEY_NAME_PACKED)
+	  if ((CurSubKeyCell->Flags & REG_KEY_ROOT_CELL) == REG_KEY_ROOT_CELL)
 	    {
-	      NameSize *= sizeof(WCHAR);
+	      /* Use name of the key object */
+	      NameSize = CurKey->Name.Length;
 	    }
+	  else
+	    {
+	      /* Use name of the key cell */
+	      NameSize = CurSubKeyCell->NameSize;
+	      if (CurSubKeyCell->Flags & REG_KEY_NAME_PACKED)
+		{
+		  NameSize *= sizeof(WCHAR);
+		}
+	    }
+	  DPRINT ("NameSize %lu\n", NameSize);
 
-	  if (MaxName < NameSize)
+	  if (NameSize > MaxName)
 	    {
 	      MaxName = NameSize;
 	    }
 	}
     }
 
+  DPRINT ("MaxName %lu\n", MaxName);
+
   return MaxName;
 }
 
@@ -3239,18 +3266,20 @@
     {
       return STATUS_INSUFFICIENT_RESOURCES;
     }
+  RtlZeroMemory (tmpBin,
+		  REG_BLOCK_SIZE);
 
   tmpBin->BlockId = REG_BIN_ID;
   tmpBin->BlockOffset = RegistryHive->FileSize - REG_BLOCK_SIZE;
   RegistryHive->FileSize += REG_BLOCK_SIZE;
   tmpBin->BlockSize = REG_BLOCK_SIZE;
   tmpBin->Unused1 = 0;
-  ZwQuerySystemTime(&tmpBin->DateModified);
+  NtQuerySystemTime(&tmpBin->DateModified);
   tmpBin->Unused2 = 0;
 
   /* Increase size of list of blocks */
   tmpBlockList = ExAllocatePool(NonPagedPool,
-	  sizeof(PHBIN *) * (RegistryHive->BlockListSize + 1));
+				sizeof(PHBIN *) * (RegistryHive->BlockListSize + 1));
   if (tmpBlockList == NULL)
     {
       ExFreePool(tmpBin);
@@ -3319,12 +3348,10 @@
 		 BLOCK_OFFSET *CellOffset)
 {
   PCELL_HEADER NewCell;
-  NTSTATUS Status;
-  PHBIN pBin;
+  PHBIN Bin;
   ULONG i;
   PVOID Temp;
-
-  Status = STATUS_SUCCESS;
+  NTSTATUS Status;
 
   /* Round to 16 bytes multiple */
   CellSize = ROUND_UP(CellSize, 16);
@@ -3333,20 +3360,18 @@
   if (IsPointerHive(RegistryHive))
     {
       NewCell = ExAllocatePool(NonPagedPool, CellSize);
-
       if (NewCell == NULL)
 	{
-	  Status = STATUS_INSUFFICIENT_RESOURCES;
+	  return STATUS_INSUFFICIENT_RESOURCES;
 	}
-      else
-	{
-	  RtlZeroMemory(NewCell, CellSize);
-	  NewCell->CellSize = -CellSize;
 
-	  *Cell = NewCell;
-	  if (CellOffset != NULL)
-	    *CellOffset = (BLOCK_OFFSET) NewCell;
-	}
+      RtlZeroMemory (NewCell,
+		     CellSize);
+      NewCell->CellSize = -CellSize;
+
+      *Cell = NewCell;
+      if (CellOffset != NULL)
+	*CellOffset = (BLOCK_OFFSET) NewCell;
     }
   else
     {
@@ -3361,18 +3386,17 @@
 		*CellOffset = RegistryHive->FreeListOffset[i];
 
 	      /* Update time of heap */
-	      Temp = CmiGetCell (RegistryHive, RegistryHive->FreeListOffset[i], &pBin);
+	      Temp = CmiGetCell (RegistryHive,
+				 RegistryHive->FreeListOffset[i],
+				 &Bin);
 	      if (Temp == NULL)
 		{
 		  DPRINT("CmiGetBlock() failed\n");
 		  return STATUS_UNSUCCESSFUL;
 		}
 
-	      if (Temp)
-		{
-		  NtQuerySystemTime(&pBin->DateModified);
-		  CmiMarkBlockDirty(RegistryHive, RegistryHive->FreeListOffset[i]);
-		}
+	      NtQuerySystemTime(&Bin->DateModified);
+	      CmiMarkBlockDirty(RegistryHive, RegistryHive->FreeListOffset[i]);
 
 	      if ((i + 1) < RegistryHive->FreeListSize)
 		{
@@ -3395,35 +3419,35 @@
 	{
 	  /* Add a new bin */
 	  Status = CmiAddBin(RegistryHive, (PVOID *) &NewCell , CellOffset);
+	  if (!NT_SUCCESS(Status))
+	    return Status;
 	}
 
-      if (NT_SUCCESS(Status))
-	{
-	  *Cell = NewCell;
-
-	  /* Split the block in two parts */
-	  if (NewCell->CellSize > CellSize)
-	    {
-	      NewCell = (PCELL_HEADER) ((ULONG_PTR) NewCell + CellSize);
-	      NewCell->CellSize = ((PCELL_HEADER) (*Cell))->CellSize - CellSize;
-	      CmiAddFree(RegistryHive,
-			 NewCell,
-			 *CellOffset + CellSize,
-			 TRUE);
-	      CmiMarkBlockDirty(RegistryHive,
-				*CellOffset + CellSize);
-	    }
-	  else if (NewCell->CellSize < CellSize)
-	    {
-	      return(STATUS_UNSUCCESSFUL);
-	    }
+      *Cell = NewCell;
 
-	  RtlZeroMemory(*Cell, CellSize);
-	  ((PCELL_HEADER) (*Cell))->CellSize = -CellSize;
+      /* Split the block in two parts */
+      if (NewCell->CellSize > CellSize)
+	{
+	  NewCell = (PCELL_HEADER) ((ULONG_PTR) NewCell + CellSize);
+	  NewCell->CellSize = ((PCELL_HEADER) (*Cell))->CellSize - CellSize;
+	  CmiAddFree(RegistryHive,
+		     NewCell,
+		     *CellOffset + CellSize,
+		     TRUE);
+	  CmiMarkBlockDirty(RegistryHive,
+			    *CellOffset + CellSize);
 	}
+      else if (NewCell->CellSize < CellSize)
+	{
+	  return STATUS_UNSUCCESSFUL;
+	}
+
+      RtlZeroMemory(*Cell,
+		    CellSize);
+      ((PCELL_HEADER) (*Cell))->CellSize = -CellSize;
     }
 
-  return(Status);
+  return STATUS_SUCCESS;
 }
 
 

reactos/ntoskrnl/cm
registry.c 1.122 -> 1.123
diff -u -r1.122 -r1.123
--- registry.c	7 Mar 2004 19:59:36 -0000	1.122
+++ registry.c	13 Mar 2004 12:14:44 -0000	1.123
@@ -1,4 +1,4 @@
-/* $Id: registry.c,v 1.122 2004/03/07 19:59:36 hbirr Exp $
+/* $Id: registry.c,v 1.123 2004/03/13 12:14:44 ekohl Exp $
  *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
@@ -525,7 +525,7 @@
 			CmiKeyType);
   if (!NT_SUCCESS(Status))
     {
-      return(Status);
+      return Status;
     }
 
   DPRINT ("RemainingPath %wZ\n", &RemainingPath);
@@ -537,12 +537,13 @@
       return STATUS_OBJECT_NAME_COLLISION;
     }
 
-  /* If RemainingPath contains \ we must return error
-     because CmiConnectHive() can not create trees */
+  /* Ignore leading backslash */
   SubName = RemainingPath.Buffer;
   if (*SubName == L'\\')
     SubName++;
 
+  /* If RemainingPath contains \ we must return error
+     because CmiConnectHive() can not create trees */
   if (wcschr (SubName, L'\\') != NULL)
     {
       ObDereferenceObject (ParentKey);
@@ -575,38 +576,39 @@
   NewKey->KeyCell = CmiGetCell (RegistryHive, NewKey->KeyCellOffset, NULL);
   NewKey->Flags = 0;
   NewKey->NumberOfSubKeys = 0;
-  NewKey->SubKeys = ExAllocatePool(PagedPool,
-                                   NewKey->KeyCell->NumberOfSubKeys * sizeof(ULONG));
-
-  if ((NewKey->SubKeys == NULL) && (NewKey->KeyCell->NumberOfSubKeys != 0))
+  if (NewKey->KeyCell->NumberOfSubKeys != 0)
     {
-      DPRINT("NumberOfSubKeys %d\n", NewKey->KeyCell->NumberOfSubKeys);
-      ObDereferenceObject (NewKey);
-      ObDereferenceObject (ParentKey);
-      RtlFreeUnicodeString(&RemainingPath);
-      return STATUS_INSUFFICIENT_RESOURCES;
+      NewKey->SubKeys = ExAllocatePool(PagedPool,
+				       NewKey->KeyCell->NumberOfSubKeys * sizeof(ULONG));
+      if (NewKey->SubKeys == NULL)
+	{
+	  DPRINT("ExAllocatePool() failed\n");
+	  ObDereferenceObject (NewKey);
+	  ObDereferenceObject (ParentKey);
+	  RtlFreeUnicodeString(&RemainingPath);
+	  return STATUS_INSUFFICIENT_RESOURCES;
+	}
     }
-
-  if (SubName == RemainingPath.Buffer)
+  else
     {
-      NewKey->Name = RemainingPath;
+      NewKey->SubKeys = NULL;
     }
-  else
+
+  DPRINT ("SubName %S\n", SubName);
+
+  Status = RtlCreateUnicodeString(&NewKey->Name,
+				  SubName);
+  RtlFreeUnicodeString(&RemainingPath);
+  if (!NT_SUCCESS(Status))
     {
-      Status = RtlCreateUnicodeString(&NewKey->Name,
-				      SubName);
-      RtlFreeUnicodeString(&RemainingPath);
-      if (!NT_SUCCESS(Status))
-        {
-          DPRINT1("RtlCreateUnicodeString() failed (Status %lx)\n", Status);
-          if (NewKey->SubKeys != NULL)
-	    {
-	      ExFreePool (NewKey->SubKeys);
-	    }
-          ObDereferenceObject (NewKey);
-          ObDereferenceObject (ParentKey);
-          return STATUS_INSUFFICIENT_RESOURCES;
+      DPRINT1("RtlCreateUnicodeString() failed (Status %lx)\n", Status);
+      if (NewKey->SubKeys != NULL)
+	{
+	  ExFreePool (NewKey->SubKeys);
 	}
+      ObDereferenceObject (NewKey);
+      ObDereferenceObject (ParentKey);
+      return STATUS_INSUFFICIENT_RESOURCES;
     }
 
   CmiAddKeyToList (ParentKey, NewKey);
CVSspam 0.2.8