]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFw: Exit with error when header lookup fails
authorMichael LeMay <michael.lemay@intel.com>
Fri, 29 Jan 2016 03:23:21 +0000 (11:23 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 17 Feb 2016 05:17:26 +0000 (13:17 +0800)
This patch revises GetPhdrByIndex and GetShdrByIndex to cause GenFw to
exit with an error message when a section header lookup fails.  The
current behavior of those functions in such circumstances is to return
NULL, which can cause GenFw to subsequently fault when it attempts to
dereference the null pointer.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael LeMay <michael.lemay@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/C/GenFw/Elf32Convert.c
BaseTools/Source/C/GenFw/Elf64Convert.c

index 9bf58555c076c88a8cef657a7d2a4f98e4c37aac..dbdf05671bd19979c32969ba267ce660fcb77576 100644 (file)
@@ -191,8 +191,11 @@ GetShdrByIndex (
   UINT32 Num\r
   )\r
 {\r
-  if (Num >= mEhdr->e_shnum)\r
-    return NULL;\r
+  if (Num >= mEhdr->e_shnum) {\r
+    Error (NULL, 0, 3000, "Invalid", "GetShdrByIndex: Index %u is too high.", Num);\r
+    exit(EXIT_FAILURE);\r
+  }\r
+\r
   return (Elf_Shdr*)((UINT8*)mShdrBase + Num * mEhdr->e_shentsize);\r
 }\r
 \r
@@ -203,7 +206,8 @@ GetPhdrByIndex (
   )\r
 {\r
   if (num >= mEhdr->e_phnum) {\r
-    return NULL;\r
+    Error (NULL, 0, 3000, "Invalid", "GetPhdrByIndex: Index %u is too high.", num);\r
+    exit(EXIT_FAILURE);\r
   }\r
 \r
   return (Elf_Phdr *)((UINT8*)mPhdrBase + num * mEhdr->e_phentsize);\r
index fb85b3821b38afa044e92541aa762f249baf9ed8..974f3ca53a3ebf1f4d2cec57c5a046550226a295 100644 (file)
@@ -197,8 +197,11 @@ GetShdrByIndex (
   UINT32 Num\r
   )\r
 {\r
-  if (Num >= mEhdr->e_shnum)\r
-    return NULL;\r
+  if (Num >= mEhdr->e_shnum) {\r
+    Error (NULL, 0, 3000, "Invalid", "GetShdrByIndex: Index %u is too high.", Num);\r
+    exit(EXIT_FAILURE);\r
+  }\r
+\r
   return (Elf_Shdr*)((UINT8*)mShdrBase + Num * mEhdr->e_shentsize);\r
 }\r
 \r