Enhance the error code info.
authorydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 11 Sep 2012 10:53:37 +0000 (10:53 +0000)
committerydong10 <ydong10@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 11 Sep 2012 10:53:37 +0000 (10:53 +0000)
Signed-off-by: Dong Eric <eric.dong@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13716 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Include/Library/PeCoffLib.h
MdePkg/Library/BasePeCoffLib/BasePeCoff.c

index 09c7b83..9ed6d61 100644 (file)
@@ -34,6 +34,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define IMAGE_ERROR_SECTION_NOT_LOADED           8\r
 #define IMAGE_ERROR_FAILED_RELOCATION            9\r
 #define IMAGE_ERROR_FAILED_ICACHE_FLUSH          10\r
+#define IMAGE_ERROR_UNSUPPORTED                  11\r
 \r
 /**\r
   Reads contents of a PE/COFF image.\r
index e1b4cb6..60036e1 100644 (file)
@@ -104,6 +104,9 @@ PeCoffLoaderGetPeHeader (
                            );\r
   if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
     ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+    if (Size != ReadSize) {\r
+      Status = RETURN_UNSUPPORTED;\r
+    }\r
     return Status;\r
   }\r
 \r
@@ -132,6 +135,9 @@ PeCoffLoaderGetPeHeader (
                            );\r
   if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
     ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+    if (Size != ReadSize) {\r
+      Status = RETURN_UNSUPPORTED;\r
+    }\r
     return Status;\r
   }\r
 \r
@@ -161,6 +167,7 @@ PeCoffLoaderGetPeHeader (
       // 1. Check FileHeader.SizeOfOptionalHeader filed.\r
       //\r
       if (EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES < Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes) {\r
+        ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;\r
         return RETURN_UNSUPPORTED;\r
       }\r
 \r
@@ -171,6 +178,7 @@ PeCoffLoaderGetPeHeader (
       //\r
       if (EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1 < Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes) {\r
         if (Hdr.Pe32->OptionalHeader.SizeOfHeaders < (UINT32)((UINT8 *)(&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1]) - (UINT8 *) &Hdr)) {\r
+          ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;\r
           return RETURN_UNSUPPORTED;\r
         }\r
       }\r
@@ -187,6 +195,10 @@ PeCoffLoaderGetPeHeader (
                                &BufferData\r
                                );\r
       if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
+        ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+        if (Size != ReadSize) {\r
+          Status = RETURN_UNSUPPORTED;\r
+        }\r
         return Status;\r
       }\r
 \r
@@ -202,7 +214,8 @@ PeCoffLoaderGetPeHeader (
           //\r
           if ((UINT32) (~0) - Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress <\r
               Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].Size) {\r
-            return RETURN_INVALID_PARAMETER;\r
+            ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;\r
+            return RETURN_UNSUPPORTED;\r
           }\r
 \r
           //\r
@@ -218,6 +231,10 @@ PeCoffLoaderGetPeHeader (
                                    &BufferData\r
                                    );\r
           if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
+            ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+            if (Size != ReadSize) {\r
+              Status = RETURN_UNSUPPORTED;\r
+            }\r
             return Status;\r
           }\r
         }\r
@@ -236,6 +253,7 @@ PeCoffLoaderGetPeHeader (
       // 1. Check FileHeader.SizeOfOptionalHeader filed.\r
       //\r
       if (EFI_IMAGE_NUMBER_OF_DIRECTORY_ENTRIES < Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes) {\r
+        ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;\r
         return RETURN_UNSUPPORTED;\r
       }\r
 \r
@@ -246,6 +264,7 @@ PeCoffLoaderGetPeHeader (
       //\r
       if (EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1 < Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes) {\r
         if (Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders < (UINT32)((UINT8 *)(&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY + 1]) - (UINT8 *) &Hdr)) {\r
+          ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;\r
           return RETURN_UNSUPPORTED;\r
         }\r
       }\r
@@ -262,6 +281,10 @@ PeCoffLoaderGetPeHeader (
                                &BufferData\r
                                );\r
       if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
+        ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+        if (Size != ReadSize) {\r
+          Status = RETURN_UNSUPPORTED;\r
+        }\r
         return Status;\r
       }\r
 \r
@@ -277,7 +300,8 @@ PeCoffLoaderGetPeHeader (
           //\r
           if ((UINT32) (~0) - Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].VirtualAddress <\r
               Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_SECURITY].Size) {\r
-            return RETURN_INVALID_PARAMETER;\r
+            ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;\r
+            return RETURN_UNSUPPORTED;\r
           }\r
 \r
           //\r
@@ -293,6 +317,10 @@ PeCoffLoaderGetPeHeader (
                                    &BufferData\r
                                    );\r
           if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
+            ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+            if (Size != ReadSize) {\r
+              Status = RETURN_UNSUPPORTED;\r
+            }\r
             return Status;\r
           }\r
         }\r
@@ -348,6 +376,10 @@ PeCoffLoaderGetPeHeader (
                              &SectionHeader\r
                              );\r
     if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
+      ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+      if (Size != ReadSize) {\r
+        Status = RETURN_UNSUPPORTED;\r
+      }\r
       return Status;\r
     }\r
 \r
@@ -356,7 +388,8 @@ PeCoffLoaderGetPeHeader (
       // Check the member data to avoid overflow.\r
       //\r
       if ((UINT32) (~0) - SectionHeader.PointerToRawData < SectionHeader.SizeOfRawData) {\r
-        return RETURN_INVALID_PARAMETER;\r
+        ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;\r
+        return RETURN_UNSUPPORTED;\r
       }\r
 \r
       //\r
@@ -372,6 +405,10 @@ PeCoffLoaderGetPeHeader (
                                &BufferData\r
                                );\r
       if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
+        ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+        if (Size != ReadSize) {\r
+          Status = RETURN_UNSUPPORTED;\r
+        }\r
         return Status;\r
       }\r
     }\r
@@ -507,7 +544,8 @@ PeCoffLoaderGetImageInfo (
   // 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
+    ImageContext->ImageError = IMAGE_ERROR_UNSUPPORTED;\r
+    return RETURN_UNSUPPORTED;\r
   }\r
 \r
   if (!(ImageContext->IsTeImage)) {\r
@@ -557,6 +595,9 @@ PeCoffLoaderGetImageInfo (
                                  );\r
         if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
           ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+          if (Size != ReadSize) {\r
+            Status = RETURN_UNSUPPORTED;\r
+          }\r
           return Status;\r
         }\r
 \r
@@ -585,6 +626,9 @@ PeCoffLoaderGetImageInfo (
                                    );\r
           if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
             ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+            if (Size != ReadSize) {\r
+              Status = RETURN_UNSUPPORTED;\r
+            }\r
             return Status;\r
           }\r
           if (DebugEntry.Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
@@ -620,6 +664,9 @@ PeCoffLoaderGetImageInfo (
                                );\r
       if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
         ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+        if (Size != ReadSize) {\r
+          Status = RETURN_UNSUPPORTED;\r
+        }\r
         return Status;\r
       }\r
 \r
@@ -674,6 +721,9 @@ PeCoffLoaderGetImageInfo (
                                  );\r
         if (RETURN_ERROR (Status) || (Size != ReadSize)) {\r
           ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ;\r
+          if (Size != ReadSize) {\r
+            Status = RETURN_UNSUPPORTED;\r
+          }\r
           return Status;\r
         }\r
 \r