ImageTool: Check HeaderInfo

This commit is contained in:
Marvin Häuser 2023-06-13 01:25:08 +02:00 committed by MikhailKrichanov
parent 31c0046cbe
commit f374c858df

View File

@ -92,6 +92,28 @@ CheckToolImageSegmentInfo (
return true; return true;
} }
static
bool
CheckToolImageHeaderInfo (
const image_tool_header_info_t *HeaderInfo,
const image_tool_segment_info_t *SegmentInfo,
uint32_t ImageSize
)
{
if (SegmentInfo->Segments[0].ImageAddress > HeaderInfo->EntryPointAddress ||
HeaderInfo->EntryPointAddress > ImageSize) {
DEBUG_RAISE ();
return false;
}
if (!IS_ALIGNED (HeaderInfo->BaseAddress, SegmentInfo->SegmentAlignment)) {
DEBUG_RAISE ();
return false;
}
return true;
}
const image_tool_segment_t * const image_tool_segment_t *
ImageGetSegmentByAddress ( ImageGetSegmentByAddress (
uint32_t *Address, uint32_t *Address,
@ -296,6 +318,16 @@ CheckToolImage (
return false; return false;
} }
Result = CheckToolImageHeaderInfo (
&Image->HeaderInfo,
&Image->SegmentInfo,
ImageSize
);
if (!Result) {
DEBUG_RAISE ();
return false;
}
Result = CheckToolImageRelocInfo (Image, ImageSize); Result = CheckToolImageRelocInfo (Image, ImageSize);
if (!Result) { if (!Result) {
DEBUG_RAISE (); DEBUG_RAISE ();
@ -371,10 +403,15 @@ ToolImageRelocate (
uint32_t RelocTarget32; uint32_t RelocTarget32;
uint64_t RelocTarget64; uint64_t RelocTarget64;
if (!IS_ALIGNED (BaseAddress, Image->SegmentInfo.SegmentAlignment)) {
DEBUG_RAISE ();
return false;
}
Adjust = BaseAddress - Image->HeaderInfo.BaseAddress; Adjust = BaseAddress - Image->HeaderInfo.BaseAddress;
if (Adjust == 0) { if (Adjust == 0) {
return TRUE; return true;
} }
for (Index = 0; Index < Image->RelocInfo.NumRelocs; ++Index) { for (Index = 0; Index < Image->RelocInfo.NumRelocs; ++Index) {