]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BasePeCoffLib/BasePeCoff.c
Update IfConfig.c to use TPL_CALLBACK instead of TPL_CALLBACK - 1 to follow UEFI...
[mirror_edk2.git] / MdePkg / Library / BasePeCoffLib / BasePeCoff.c
index af8af8a0a81e766d19dd5b9b015fbb3ed4c4eb91..8b2a78e448dda99a2ce839c4397296325e8f09a3 100644 (file)
@@ -2,7 +2,7 @@
   Base PE/COFF loader supports loading any PE32/PE32+ or TE image, but\r
   only supports relocating IA32, x64, IPF, and EBC images.\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
   Portions copyright (c) 2008 - 2009, Apple Inc. 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
@@ -270,7 +270,7 @@ PeCoffLoaderGetImageInfo (
   // Obviously having base relocations with RELOCS_STRIPPED==1 is invalid.\r
   //\r
   // Look at the file header to determine if relocations have been stripped, and\r
-  // save this info in the image context for later use.\r
+  // save this information in the image context for later use.\r
   //\r
   if ((!(ImageContext->IsTeImage)) && ((Hdr.Pe32->FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0)) {\r
     ImageContext->RelocationsStripped = TRUE;\r
@@ -279,6 +279,14 @@ PeCoffLoaderGetImageInfo (
   } else {\r
     ImageContext->RelocationsStripped = FALSE;\r
   }\r
+  \r
+  //\r
+  // TE Image Relocation Data Directory Entry size is non-zero, but the Relocation Data Directory Virtual Address is zero.\r
+  // This case is not a valid TE image. \r
+  //\r
+  if ((ImageContext->IsTeImage) && (Hdr.Te->DataDirectory[0].Size != 0) && (Hdr.Te->DataDirectory[0].VirtualAddress == 0)) {\r
+    return RETURN_INVALID_PARAMETER;\r
+  }\r
 \r
   if (!(ImageContext->IsTeImage)) {\r
     if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
@@ -347,7 +355,7 @@ PeCoffLoaderGetImageInfo (
           Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
           Status = ImageContext->ImageRead (\r
                                    ImageContext->Handle,\r
-                                   DebugDirectoryEntryFileOffset,\r
+                                   DebugDirectoryEntryFileOffset + Index,\r
                                    &Size,\r
                                    &DebugEntry\r
                                    );\r
@@ -434,7 +442,7 @@ PeCoffLoaderGetImageInfo (
         Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY);\r
         Status = ImageContext->ImageRead (\r
                                  ImageContext->Handle,\r
-                                 DebugDirectoryEntryFileOffset,\r
+                                 DebugDirectoryEntryFileOffset + Index,\r
                                  &Size,\r
                                  &DebugEntry\r
                                  );\r
@@ -821,6 +829,7 @@ PeCoffLoaderLoadImage (
   EFI_IMAGE_RESOURCE_DIRECTORY_ENTRY    *ResourceDirectoryEntry;\r
   EFI_IMAGE_RESOURCE_DIRECTORY_STRING   *ResourceDirectoryString;\r
   EFI_IMAGE_RESOURCE_DATA_ENTRY         *ResourceDataEntry;\r
+  CHAR16                                *String;\r
 \r
 \r
   ASSERT (ImageContext != NULL);\r
@@ -831,7 +840,7 @@ PeCoffLoaderLoadImage (
   ImageContext->ImageError = IMAGE_ERROR_SUCCESS;\r
 \r
   //\r
-  // Copy the provided context info into our local version, get what we\r
+  // Copy the provided context information into our local version, get what we\r
   // can from the original image, and then use that to make sure everything\r
   // is legit.\r
   //\r
@@ -1079,7 +1088,7 @@ PeCoffLoaderLoadImage (
   ImageContext->FixupData = NULL;\r
 \r
   //\r
-  // Load the Codeview info if present\r
+  // Load the Codeview information if present\r
   //\r
   if (ImageContext->DebugDirectoryEntryRva != 0) {\r
     if (!(ImageContext->IsTeImage)) {\r
@@ -1201,11 +1210,12 @@ PeCoffLoaderLoadImage (
         for (Index = 0; Index < ResourceDirectory->NumberOfNamedEntries; Index++) {\r
           if (ResourceDirectoryEntry->u1.s.NameIsString) {\r
             ResourceDirectoryString = (EFI_IMAGE_RESOURCE_DIRECTORY_STRING *) (Base + ResourceDirectoryEntry->u1.s.NameOffset);\r
+            String = &ResourceDirectoryString->String[0];\r
 \r
             if (ResourceDirectoryString->Length == 3 &&\r
-                ResourceDirectoryString->String[0] == L'H' &&\r
-                ResourceDirectoryString->String[1] == L'I' &&\r
-                ResourceDirectoryString->String[2] == L'I') {\r
+                String[0] == L'H' &&\r
+                String[1] == L'I' &&\r
+                String[2] == L'I') {\r
               //\r
               // Resource Type "HII" found\r
               //\r