BaseTools: Fix Section header size larger than elf file size bug

Add the logic to handle the case that Section header size larger than
elf file size.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Yunhua Feng
2018-06-01 17:21:02 +08:00
committed by Yonghong Zhu
parent 3f02180031
commit d78675d195
4 changed files with 24 additions and 5 deletions

View File

@@ -670,6 +670,9 @@ WriteSections64 (
switch (Shdr->sh_type) {
case SHT_PROGBITS:
/* Copy. */
if (Shdr->sh_offset + Shdr->sh_size > mFileBufferSize) {
return FALSE;
}
memcpy(mCoffFile + mCoffSectionsOffset[Idx],
(UINT8*)mEhdr + Shdr->sh_offset,
(size_t) Shdr->sh_size);