mirror of https://github.com/acidanthera/audk.git
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>
This commit is contained in:
parent
6731c20f28
commit
17751c5fa4
|
@ -191,8 +191,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);
|
||||
}
|
||||
|
||||
|
@ -203,7 +206,8 @@ GetPhdrByIndex (
|
|||
)
|
||||
{
|
||||
if (num >= mEhdr->e_phnum) {
|
||||
return NULL;
|
||||
Error (NULL, 0, 3000, "Invalid", "GetPhdrByIndex: Index %u is too high.", num);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return (Elf_Phdr *)((UINT8*)mPhdrBase + num * mEhdr->e_phentsize);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue