Skip to content

Commit

Permalink
UefiPayloadPkg: CbParseLib: Fix integer overflow
Browse files Browse the repository at this point in the history
The IMD entry uses the 32bit start field as relative offset
to root. On Ia32X64 this works fine as UINTN is also 32 bit and
negative relative offsets are properly calculated due to an
integer overflow.

On X64 this doesn't work as UINTN is 64 bit and the offset
is no longer subtracted, but it's added to the root. Fix that
by sign extending the start field to 64 bit.

Test: Booting UefiPayloadPkg still works on Ia32X64 and now also
      works on X64.

Signed-off-by: Patrick Rudolph <[email protected]>
Reviewed-by: Gua Guo <[email protected]>
Reviewed-by: Sean Rhodes <[email protected]>
  • Loading branch information
PatrickRudolph authored and mergify[bot] committed Jan 22, 2024
1 parent 0c6d29b commit 0b09397
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion UefiPayloadPkg/Library/CbParseLib/CbParseLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ FindCbMemTable (
for (Idx = 0; Idx < Root->num_entries; Idx++) {
if (Entries[Idx].id == TableId) {
if (IsImdEntry) {
*MemTable = (VOID *)((UINTN)Entries[Idx].start + (UINTN)Root);
*MemTable = (VOID *)((INTN)(INT32)Entries[Idx].start + (UINTN)Root);
} else {
*MemTable = (VOID *)(UINTN)Entries[Idx].start;
}
Expand Down

0 comments on commit 0b09397

Please sign in to comment.