]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c
Fix the potential address overflow issue when checking PE signature.
[mirror_edk2.git] / UefiCpuPkg / Library / CpuExceptionHandlerLib / CpuExceptionCommon.c
index c075d5f168dde4b4e5f9a05de5f0804aedef44aa..0754aa983201939a081c26147e5bdf1a6e866aa3 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   CPU Exception Hanlder Library common functions.\r
 \r
-  Copyright (c) 2012 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -90,13 +90,18 @@ FindModuleImageBase (
       // DOS image header is present, so read the PE header after the DOS image header.\r
       //\r
       Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
-      if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
-        //\r
-        // It's PE image.\r
-        //\r
-        InternalPrintMessage ("!!!! Find PE image ");\r
-        *EntryPoint = (UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff);\r
-        break;\r
+      //\r
+      // Make sure PE header address does not overflow and is less than the initial address.\r
+      //\r
+      if (((UINTN)Hdr.Pe32 > Pe32Data) && ((UINTN)Hdr.Pe32 < CurrentEip)) {\r
+        if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+          //\r
+          // It's PE image.\r
+          //\r
+          InternalPrintMessage ("!!!! Find PE image ");\r
+          *EntryPoint = (UINTN)Pe32Data + (UINTN)(Hdr.Pe32->OptionalHeader.AddressOfEntryPoint & 0x0ffffffff);\r
+          break;\r
+        }\r
       }\r
     } else {\r
       //\r