[ros-diffs] [jgardou] 54460: [FREELDR] - fix potential integer overflow : casting ULONGLONG to ULONG_PTR is not a good idea.

jgardou at svn.reactos.org jgardou at svn.reactos.org
Sun Nov 20 17:37:21 UTC 2011


Author: jgardou
Date: Sun Nov 20 17:37:20 2011
New Revision: 54460

URL: http://svn.reactos.org/svn/reactos?rev=54460&view=rev
Log:
[FREELDR]
- fix potential integer overflow : casting ULONGLONG to ULONG_PTR is not a good idea.

Modified:
    trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c

Modified: trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c?rev=54460&r1=54459&r2=54460&view=diff
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/i386/pcmem.c [iso-8859-1] Sun Nov 20 17:37:20 2011
@@ -248,10 +248,10 @@
       /* Copy data to global buffer */
       RtlCopyMemory(&PcBiosMemoryMap[PcBiosMapCount], (PVOID)BIOSCALLBUFFER, Regs.x.ecx);
 
-      TRACE("BaseAddress: 0x%p\n", (PVOID)(ULONG_PTR)PcBiosMemoryMap[PcBiosMapCount].BaseAddress);
-      TRACE("Length: 0x%p\n", (PVOID)(ULONG_PTR)PcBiosMemoryMap[PcBiosMapCount].Length);
-      TRACE("Type: 0x%x\n", PcBiosMemoryMap[PcBiosMapCount].Type);
-      TRACE("Reserved: 0x%x\n", PcBiosMemoryMap[PcBiosMapCount].Reserved);
+      TRACE("BaseAddress: 0x%llx\n", PcBiosMemoryMap[PcBiosMapCount].BaseAddress);
+      TRACE("Length: 0x%llx\n", PcBiosMemoryMap[PcBiosMapCount].Length);
+      TRACE("Type: 0x%lx\n", PcBiosMemoryMap[PcBiosMapCount].Type);
+      TRACE("Reserved: 0x%lx\n", PcBiosMemoryMap[PcBiosMapCount].Reserved);
       TRACE("\n");
 
       /* Check if this is free memory */
@@ -260,13 +260,12 @@
           MemoryType = LoaderFree;
 
           /* Align up base of memory area */
-          RealBaseAddress = ALIGN_UP_BY(PcBiosMemoryMap[PcBiosMapCount].BaseAddress,
-                                        MM_PAGE_SIZE);
+          RealBaseAddress = PcBiosMemoryMap[PcBiosMapCount].BaseAddress & ~(MM_PAGE_SIZE - 1ULL);
 
           /* Calculate the length after aligning the base */
           RealSize = PcBiosMemoryMap[PcBiosMapCount].BaseAddress +
                      PcBiosMemoryMap[PcBiosMapCount].Length - RealBaseAddress;
-          RealSize = ALIGN_DOWN_BY(RealSize, MM_PAGE_SIZE);
+          RealSize = (RealSize + MM_PAGE_SIZE - 1) & ~(MM_PAGE_SIZE - 1ULL);
       }
       else
       {
@@ -276,13 +275,11 @@
              MemoryType = LoaderSpecialMemory;
 
           /* Align down base of memory area */
-          RealBaseAddress = ALIGN_DOWN_BY(PcBiosMemoryMap[PcBiosMapCount].BaseAddress,
-                                          MM_PAGE_SIZE);
-
+          RealBaseAddress = PcBiosMemoryMap[PcBiosMapCount].BaseAddress & ~(MM_PAGE_SIZE - 1ULL);
           /* Calculate the length after aligning the base */
           RealSize = PcBiosMemoryMap[PcBiosMapCount].BaseAddress +
                      PcBiosMemoryMap[PcBiosMapCount].Length - RealBaseAddress;
-          RealSize = ALIGN_UP_BY(RealSize, MM_PAGE_SIZE);
+          RealSize = (RealSize + MM_PAGE_SIZE - 1) & ~(MM_PAGE_SIZE - 1ULL);
       }
 
       /* Check if we can add this descriptor */




More information about the Ros-diffs mailing list