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>
switch (Shdr->sh_type) {\r
case SHT_PROGBITS:\r
/* Copy. */\r
switch (Shdr->sh_type) {\r
case SHT_PROGBITS:\r
/* Copy. */\r
+ if (Shdr->sh_offset + Shdr->sh_size > mFileBufferSize) {\r
+ return FALSE;\r
+ }\r
memcpy(mCoffFile + mCoffSectionsOffset[Idx],\r
(UINT8*)mEhdr + Shdr->sh_offset,\r
Shdr->sh_size);\r
memcpy(mCoffFile + mCoffSectionsOffset[Idx],\r
(UINT8*)mEhdr + Shdr->sh_offset,\r
Shdr->sh_size);\r
switch (Shdr->sh_type) {\r
case SHT_PROGBITS:\r
/* Copy. */\r
switch (Shdr->sh_type) {\r
case SHT_PROGBITS:\r
/* Copy. */\r
+ if (Shdr->sh_offset + Shdr->sh_size > mFileBufferSize) {\r
+ return FALSE;\r
+ }\r
memcpy(mCoffFile + mCoffSectionsOffset[Idx],\r
(UINT8*)mEhdr + Shdr->sh_offset,\r
(size_t) Shdr->sh_size);\r
memcpy(mCoffFile + mCoffSectionsOffset[Idx],\r
(UINT8*)mEhdr + Shdr->sh_offset,\r
(size_t) Shdr->sh_size);\r
/** @file\r
Elf convert solution\r
\r
/** @file\r
Elf convert solution\r
\r
-Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
\r
This program and the accompanying materials are licensed and made available \r
under the terms and conditions of the BSD License which accompanies this \r
\r
This program and the accompanying materials are licensed and made available \r
under the terms and conditions of the BSD License which accompanies this \r
//\r
UINT32 mTableOffset;\r
\r
//\r
UINT32 mTableOffset;\r
\r
+//\r
+//mFileBufferSize\r
+//\r
+UINT32 mFileBufferSize;\r
+\r
//\r
//*****************************************************************************\r
// Common ELF Functions\r
//\r
//*****************************************************************************\r
// Common ELF Functions\r
ELF_FUNCTION_TABLE ElfFunctions;\r
UINT8 EiClass;\r
\r
ELF_FUNCTION_TABLE ElfFunctions;\r
UINT8 EiClass;\r
\r
+ mFileBufferSize = *FileLength;\r
//\r
// Determine ELF type and set function table pointer correctly.\r
//\r
//\r
// Determine ELF type and set function table pointer correctly.\r
//\r
// Write and relocate sections.\r
//\r
VerboseMsg ("Write and relocate sections.");\r
// Write and relocate sections.\r
//\r
VerboseMsg ("Write and relocate sections.");\r
- ElfFunctions.WriteSections (SECTION_TEXT);\r
- ElfFunctions.WriteSections (SECTION_DATA);\r
- ElfFunctions.WriteSections (SECTION_HII);\r
+ if (!ElfFunctions.WriteSections (SECTION_TEXT)) {\r
+ return FALSE;\r
+ }\r
+ if (!ElfFunctions.WriteSections (SECTION_DATA)) {\r
+ return FALSE;\r
+ }\r
+ if (!ElfFunctions.WriteSections (SECTION_HII)) {\r
+ return FALSE;\r
+ }\r
\r
//\r
// Translate and write relocations.\r
\r
//\r
// Translate and write relocations.\r
/** @file\r
Header file for Elf convert solution\r
\r
/** @file\r
Header file for Elf convert solution\r
\r
-Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>\r
\r
This program and the accompanying materials are licensed and made available \r
under the terms and conditions of the BSD License which accompanies this \r
\r
This program and the accompanying materials are licensed and made available \r
under the terms and conditions of the BSD License which accompanies this \r
extern UINT8 *mCoffFile;\r
extern UINT32 mTableOffset;\r
extern UINT32 mOutImageType;\r
extern UINT8 *mCoffFile;\r
extern UINT32 mTableOffset;\r
extern UINT32 mOutImageType;\r
+extern UINT32 mFileBufferSize;\r
\r
//\r
// Common EFI specific data.\r
\r
//\r
// Common EFI specific data.\r