ImageTool: Enforce reloc disjointness

This commit is contained in:
Marvin Häuser 2023-06-13 02:18:01 +02:00 committed by MikhailKrichanov
parent b25125e0e1
commit 5fb01f8f29

View File

@ -166,11 +166,11 @@ static
bool bool
CheckToolImageReloc ( CheckToolImageReloc (
const image_tool_image_info_t *Image, const image_tool_image_info_t *Image,
const image_tool_reloc_t *Reloc const image_tool_reloc_t *Reloc,
uint8_t RelocSize
) )
{ {
uint32_t RelocOffset; uint32_t RelocOffset;
uint8_t RelocSize;
uint32_t RemainingSize; uint32_t RemainingSize;
const image_tool_segment_t *Segment; const image_tool_segment_t *Segment;
uint16_t MovHigh; uint16_t MovHigh;
@ -187,12 +187,6 @@ CheckToolImageReloc (
return false; return false;
} }
RelocSize = ToolImageGetRelocSize (Reloc->Type);
if (RelocSize == 0) {
DEBUG_RAISE ();
return false;
}
if (RelocSize > RemainingSize) { if (RelocSize > RemainingSize) {
DEBUG_RAISE (); DEBUG_RAISE ();
return false; return false;
@ -232,7 +226,8 @@ CheckToolImageRelocInfo (
) )
{ {
const image_tool_reloc_info_t *RelocInfo; const image_tool_reloc_info_t *RelocInfo;
uint32_t PrevTarget; uint8_t RelocSize;
uint32_t MinRelocTarget;
uint32_t Index; uint32_t Index;
bool Result; bool Result;
@ -252,21 +247,27 @@ CheckToolImageRelocInfo (
return false; return false;
} }
PrevTarget = 0; MinRelocTarget = 0;
for (Index = 0; Index < RelocInfo->NumRelocs; ++Index) { for (Index = 0; Index < RelocInfo->NumRelocs; ++Index) {
if (RelocInfo->Relocs[Index].Target < PrevTarget) { if (RelocInfo->Relocs[Index].Target < MinRelocTarget) {
assert (false); DEBUG_RAISE ();
return false; return false;
} }
Result = CheckToolImageReloc (Image, ImageSize, &RelocInfo->Relocs[Index]); RelocSize = ToolImageGetRelocSize (RelocInfo->Relocs[Index].Type);
if (RelocSize == 0) {
DEBUG_RAISE ();
return false;
}
Result = CheckToolImageReloc (Image, &RelocInfo->Relocs[Index], RelocSize);
if (!Result) { if (!Result) {
DEBUG_RAISE (); DEBUG_RAISE ();
return false; return false;
} }
PrevTarget = RelocInfo->Relocs[Index].Target; MinRelocTarget = RelocInfo->Relocs[Index].Target + RelocSize;
} }
return true; return true;