Correctly interpret the cell type in CmiDestroyCell. Patch by brbak <mpd000@yahoo...
[reactos.git] / reactos / ntoskrnl / cm / regfile.c
index 5479ec9..03d9db9 100644 (file)
@@ -1,5 +1,5 @@
 /* $Id$
- * 
+ *
  * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/cm/regfile.c
@@ -20,8 +20,6 @@
 
 /* LOCAL MACROS *************************************************************/
 
-#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
-
 #define ABS_VALUE(V) (((V) < 0) ? -(V) : (V))
 
 BOOLEAN CmiDoVerify = FALSE;
@@ -105,7 +103,7 @@ CmiVerifyBinHeader(PHBIN BinHeader)
 
   //BinHeader->DateModified.dwHighDateTime
 
-  
+
   if (BinHeader->BinSize != REG_BLOCK_SIZE)
     {
       DbgPrint("BinSize is %.08x (should be a multiple of %.08x)\n",
@@ -398,8 +396,6 @@ CmiCreateNewRegFile(HANDLE FileHandle)
 
   ExFreePool(Buffer);
 
-  ASSERTMSG(NT_SUCCESS(Status), ("Status: 0x%X\n", Status));
-
   if (!NT_SUCCESS(Status))
     {
       return(Status);
@@ -688,9 +684,8 @@ CmiImportHiveBins(PREGISTRY_HIVE Hive,
          return STATUS_REGISTRY_CORRUPT;
        }
 
-      ASSERTMSG((Bin->BinSize % REG_BLOCK_SIZE) == 0,
-               ("Bin size (0x%.08x) must be multiple of 4K\n",
-               Bin->BinSize));
+      ASSERTMSG("Bin size must be multiple of 4K\n",
+                (Bin->BinSize % REG_BLOCK_SIZE) == 0);
 
       /* Allocate the hive block */
       Hive->BlockList[BlockIndex].Bin = ExAllocatePool (PagedPool,
@@ -864,18 +859,19 @@ CmiInitNonVolatileRegistryHive (PREGISTRY_HIVE RegistryHive,
 
   /* Duplicate Filename */
   Status = RtlCreateUnicodeString(&RegistryHive->HiveFileName,
-                                 Filename);
+                                  Filename);
   if (!NT_SUCCESS(Status))
     {
-      DPRINT("RtlCreateUnicodeString() failed (Status %lx)\n", Status);
+      DPRINT("RtlpCreateUnicodeString() failed (Status %lx)\n", Status);
       return(Status);
     }
 
   /* Create log file name */
   RegistryHive->LogFileName.Length = (wcslen(Filename) + 4) * sizeof(WCHAR);
   RegistryHive->LogFileName.MaximumLength = RegistryHive->LogFileName.Length + sizeof(WCHAR);
-  RegistryHive->LogFileName.Buffer = ExAllocatePool(NonPagedPool,
-                                                   RegistryHive->LogFileName.MaximumLength);
+  RegistryHive->LogFileName.Buffer = ExAllocatePoolWithTag(PagedPool,
+                                                          RegistryHive->LogFileName.MaximumLength,
+                                                           TAG('U', 'S', 'T', 'R'));
   if (RegistryHive->LogFileName.Buffer == NULL)
     {
       RtlFreeUnicodeString(&RegistryHive->HiveFileName);
@@ -1073,7 +1069,7 @@ CmiCreateVolatileHive(PREGISTRY_HIVE *RegistryHive)
   RtlZeroMemory (Hive,
                 sizeof(REGISTRY_HIVE));
 
-  DPRINT("Hive %x\n", Hive);
+  DPRINT("Hive 0x%p\n", Hive);
 
   Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool (NonPagedPool,
                                                   sizeof(HIVE_HEADER));
@@ -1143,7 +1139,7 @@ CmiCreateTempHive(PREGISTRY_HIVE *RegistryHive)
   RtlZeroMemory (Hive,
                 sizeof(REGISTRY_HIVE));
 
-  DPRINT ("Hive %x\n", Hive);
+  DPRINT ("Hive 0x%p\n", Hive);
 
   Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool (NonPagedPool,
                                                   REG_BLOCK_SIZE);
@@ -1156,7 +1152,7 @@ CmiCreateTempHive(PREGISTRY_HIVE *RegistryHive)
   RtlZeroMemory (Hive->HiveHeader,
                 REG_BLOCK_SIZE);
 
-  DPRINT ("HiveHeader %x\n", Hive->HiveHeader);
+  DPRINT ("HiveHeader 0x%p\n", Hive->HiveHeader);
 
   Hive->Flags = HIVE_NO_FILE;
 
@@ -1265,7 +1261,7 @@ CmiLoadHive(IN POBJECT_ATTRIBUTES KeyObjectAttributes,
   RtlZeroMemory (Hive,
                 sizeof(REGISTRY_HIVE));
 
-  DPRINT ("Hive %x\n", Hive);
+  DPRINT ("Hive 0x%p\n", Hive);
   Hive->Flags = (Flags & REG_NO_LAZY_FLUSH) ? HIVE_NO_SYNCH : 0;
 
   Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool(NonPagedPool,
@@ -2873,7 +2869,7 @@ CmiAddValueToKey(IN PREGISTRY_HIVE RegistryHive,
       CmiMarkBlockDirty(RegistryHive, KeyCellOffset);
       CmiMarkBlockDirty(RegistryHive, ValueListCellOffset);
     }
-  else if (KeyCell->NumberOfValues >= 
+  else if (KeyCell->NumberOfValues >=
           (((ULONG)ABS_VALUE(ValueListCell->CellSize) - sizeof(VALUE_LIST_CELL)) / sizeof(BLOCK_OFFSET)))
     {
 #if 0
@@ -3023,7 +3019,7 @@ CmiAllocateHashTableCell (IN PREGISTRY_HIVE RegistryHive,
 
   Status = STATUS_SUCCESS;
   *HashBlock = NULL;
-  NewHashSize = sizeof(HASH_TABLE_CELL) + 
+  NewHashSize = sizeof(HASH_TABLE_CELL) +
                (SubKeyCount * sizeof(HASH_RECORD));
   Status = CmiAllocateCell (RegistryHive,
                            NewHashSize,
@@ -3460,14 +3456,20 @@ CmiDestroyCell (PREGISTRY_HIVE RegistryHive,
   else
     {
       PCELL_HEADER pFree = Cell;
+      PHASH_TABLE_CELL pHash = Cell;
+      LONG CellSize;
 
-      if (pFree->CellSize < 0)
-        pFree->CellSize = -pFree->CellSize;
-
-      /* Clear block (except the block size) */
-      RtlZeroMemory(((char*)pFree) + sizeof(ULONG),
-                   pFree->CellSize - sizeof(ULONG));
-
+      if (pHash->Id == REG_HASH_TABLE_CELL_ID)
+        CellSize = sizeof(HASH_TABLE_CELL) + pHash->HashTableSize * sizeof(HASH_RECORD);
+      else
+        CellSize = abs(pFree->CellSize);
+
+      /* Clear block */
+      RtlZeroMemory(pFree, CellSize);
+      
+      /* restore CellSize */
+      pFree->CellSize = CellSize;
+      
       /* Add block to the list of free blocks */
       CmiAddFree(RegistryHive, Cell, CellOffset, TRUE);
 
@@ -4069,6 +4071,10 @@ CmiCopyKey (PREGISTRY_HIVE DstHive,
        }
       NewKeyCell->HashTableOffset = NewHashTableOffset;
     }
+  else
+    {
+      NewHashTableCell = NULL;
+    }
 
   /* Allocate and copy value list and values */
   if (SrcKeyCell->NumberOfValues != 0)