summaryrefslogtreecommitdiff
path: root/BaseTools/Source/C/GenFw/Elf64Convert.c
diff options
context:
space:
mode:
authorMichael LeMay <michael.lemay@intel.com>2016-01-29 11:23:21 +0800
committerYonghong Zhu <yonghong.zhu@intel.com>2016-02-17 13:17:26 +0800
commit17751c5fa473fd4f830007590d59e8d15a2d2935 (patch)
tree08160d2387fd5497c8d799d27895aa6d0c021530 /BaseTools/Source/C/GenFw/Elf64Convert.c
parent6731c20f28cf26345e58ae232f9c1fb2dad6c09e (diff)
downloadedk2-platforms-17751c5fa473fd4f830007590d59e8d15a2d2935.tar.xz
BaseTools/GenFw: Exit with error when header lookup fails
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>
Diffstat (limited to 'BaseTools/Source/C/GenFw/Elf64Convert.c')
-rw-r--r--BaseTools/Source/C/GenFw/Elf64Convert.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
index fb85b3821b..974f3ca53a 100644
--- a/BaseTools/Source/C/GenFw/Elf64Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
@@ -197,8 +197,11 @@ GetShdrByIndex (
UINT32 Num
)
{
- if (Num >= mEhdr->e_shnum)
- return NULL;
+ if (Num >= mEhdr->e_shnum) {
+ Error (NULL, 0, 3000, "Invalid", "GetShdrByIndex: Index %u is too high.", Num);
+ exit(EXIT_FAILURE);
+ }
+
return (Elf_Shdr*)((UINT8*)mShdrBase + Num * mEhdr->e_shentsize);
}