diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c index ca9ce671d1..7b3e782454 100644 --- a/src/boot/efi/boot.c +++ b/src/boot/efi/boot.c @@ -2080,8 +2080,11 @@ static VOID config_load_xbootldr( h->NumberOfPartitionEntries > 1024) continue; + if (h->SizeOfPartitionEntry > UINTN_MAX / h->NumberOfPartitionEntries) /* overflow check */ + continue; + /* Now load the GPT entry table */ - sz = ((h->SizeOfPartitionEntry * h->NumberOfPartitionEntries + 511) / 512) * 512; + sz = ALIGN_TO((UINTN) h->SizeOfPartitionEntry * (UINTN) h->NumberOfPartitionEntries, 512); entries = AllocatePool(sz); r = uefi_call_wrapper(block_io->ReadBlocks, 5, diff --git a/src/boot/efi/util.h b/src/boot/efi/util.h index 8c5e35ad25..cef127f400 100644 --- a/src/boot/efi/util.h +++ b/src/boot/efi/util.h @@ -7,6 +7,10 @@ #define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0])) #define OFFSETOF(x,y) __builtin_offsetof(x,y) +static inline UINTN ALIGN_TO(UINTN l, UINTN ali) { + return ((l + ali - 1) & ~(ali - 1)); +} + static inline const CHAR16 *yes_no(BOOLEAN b) { return b ? L"yes" : L"no"; }