[DISK]: Small fixes:
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Mon, 8 May 2017 21:34:07 +0000 (21:34 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Mon, 8 May 2017 21:34:07 +0000 (21:34 +0000)
- Check for malformed disk identifier, which must be at least 9 WCHARs long (as done by disk_new);
- Prevent possible memory leaks (missing ExFreePool's) + closing registry key.
Investigated by Lesan Ilie during tests; as part of CORE-13131.
- Make one of our hacks more readable (by me).
(We also note that this driver uses the ExAllocate/FreePool functions in the old-school way).

svn path=/trunk/; revision=74509

reactos/drivers/storage/class/disk/disk.c

index ffdd3b5..e0c7756 100644 (file)
@@ -2286,7 +2286,7 @@ Return Value:
             outputBuffer->PartitionType = diskData->PartitionType;
             outputBuffer->StartingOffset = deviceExtension->StartingOffset;
             outputBuffer->PartitionLength.QuadPart = (diskData->PartitionNumber) ?
-                deviceExtension->PartitionLength.QuadPart : 2305843009213693951LL; // HACK
+                deviceExtension->PartitionLength.QuadPart : 0x1FFFFFFFFFFFFFFFLL; // HACK
             outputBuffer->HiddenSectors = diskData->HiddenSectors;
             outputBuffer->PartitionNumber = diskData->PartitionNumber;
             outputBuffer->BootIndicator = diskData->BootIndicator;
@@ -3921,6 +3921,17 @@ Return Value:
                 ZwClose(targetKey);
 
                 if (!NT_SUCCESS(status)) {
+                    ExFreePool(keyData);
+                    continue;
+                }
+
+                if (keyData->DataLength < 9*sizeof(WCHAR)) {
+                    //
+                    // the data is too short to use (we subtract 9 chars in normal path)
+                    //
+                    DebugPrint((1, "EnumerateBusKey: Saved data was invalid, "
+                                "not enough data in registry!\n"));
+                    ExFreePool(keyData);
                     continue;
                 }
 
@@ -3943,6 +3954,7 @@ Return Value:
                                                  TRUE);
 
                 if (!NT_SUCCESS(status)) {
+                    ExFreePool(keyData);
                     continue;
                 }
 
@@ -4124,6 +4136,7 @@ Return Value:
         DebugPrint((1,
                    "SCSIDISK: ExtractBiosGeometry: Can't query configuration data (%x)\n",
                    status));
+        ZwClose(hardwareKey);
         ExFreePool(keyData);
         return;
     }