https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3d980c4a2c8786bfc1a4fd4a48f8c2c5825db1ff

commit 3d980c4a2c8786bfc1a4fd4a48f8c2c5825db1ff
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Mon Dec 7 22:52:42 2020 +0100
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Mon Dec 7 22:52:42 2020 +0100

    [NTOS:FSTUB] Addendum to 29615fee and 8d2fe541: Further remove useless 
casts.
    
    Also, fix the MBR checksum calculation (missing ~CheckSum + 1), to fix
    the calculation in accordance with how MS calculates the MBR checksums
    (and what we do as well in
    
https://github.com/reactos/reactos/blob/master/base/setup/lib/utils/partlist.c#L1581
    
https://github.com/reactos/reactos/blob/master/boot/freeldr/freeldr/arch/i386/hwdisk.c#L291
    ).
---
 ntoskrnl/fstub/fstubex.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/ntoskrnl/fstub/fstubex.c b/ntoskrnl/fstub/fstubex.c
index 16787bbd4df..84296e0a722 100644
--- a/ntoskrnl/fstub/fstubex.c
+++ b/ntoskrnl/fstub/fstubex.c
@@ -909,7 +909,7 @@ FstubReadHeaderEFI(IN PDISK_INFORMATION Disk,
         Status = FstubReadSector(Disk->DeviceObject,
                                  Disk->SectorSize,
                                  EFIHeader->PartitionEntryLBA + i,
-                                 (PUSHORT)Sector);
+                                 Sector);
         if (!NT_SUCCESS(Status))
         {
             ExFreePoolWithTag(Sector, TAG_FSTUB);
@@ -929,7 +929,7 @@ FstubReadHeaderEFI(IN PDISK_INFORMATION Disk,
         Status = FstubReadSector(Disk->DeviceObject,
                                  Disk->SectorSize,
                                  EFIHeader->PartitionEntryLBA + i,
-                                 (PUSHORT)Sector);
+                                 Sector);
         if (!NT_SUCCESS(Status))
         {
             ExFreePoolWithTag(Sector, TAG_FSTUB);
@@ -2189,7 +2189,7 @@ IoReadDiskSignature(IN PDEVICE_OBJECT DeviceObject,
     Status = FstubReadSector(DeviceObject,
                              BytesPerSector,
                              0ULL,
-                             (PUSHORT)Buffer);
+                             Buffer);
     if (!NT_SUCCESS(Status))
     {
         goto Cleanup;
@@ -2208,7 +2208,7 @@ IoReadDiskSignature(IN PDEVICE_OBJECT DeviceObject,
         Status = FstubReadSector(DeviceObject,
                                  BytesPerSector,
                                  1ULL,
-                                 (PUSHORT)Buffer);
+                                 Buffer);
         if (!NT_SUCCESS(Status))
         {
             goto Cleanup;
@@ -2245,10 +2245,11 @@ IoReadDiskSignature(IN PDEVICE_OBJECT DeviceObject,
     else
     {
         /* Compute MBR checksum */
-        for (i = 0, CheckSum = 0; i < 512; i += sizeof(INT32))
+        for (i = 0, CheckSum = 0; i < 512; i += sizeof(UINT32))
         {
             CheckSum += *(PUINT32)&Buffer[i];
         }
+        CheckSum = ~CheckSum + 1;
 
         /* Set partition table style to MBR and return signature (offset 440) 
and checksum */
         Signature->PartitionStyle = PARTITION_STYLE_MBR;

Reply via email to