From 9738f7148e3e3d63adb2def1844d4464edad71f4 Mon Sep 17 00:00:00 2001 From: phcoder Date: Fri, 11 Aug 2023 17:25:54 +0000 Subject: [PATCH] Fix GPT sanity check for 1-sector partitions --- shared/partitions.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/shared/partitions.cpp b/shared/partitions.cpp index f807c6c..905ecf2 100644 --- a/shared/partitions.cpp +++ b/shared/partitions.cpp @@ -133,8 +133,6 @@ bool GPTGetPartitions(uint8_t *block /* K_SIGNATURE_BLOCK_SIZE */, EsFileOffset partitionEntryCount = GPT_PARTITION_COUNT; } - bool foundESP = false; - for (uintptr_t i = 0; i < partitionEntryCount; i++) { uint8_t *entry = block + sectorBytes * 2 + i * partitionEntryBytes; @@ -147,22 +145,14 @@ bool GPTGetPartitions(uint8_t *block /* K_SIGNATURE_BLOCK_SIZE */, EsFileOffset continue; } - if ((!guidLow && !guidHigh) || firstLBA >= sectorCount || lastLBA >= sectorCount || firstLBA >= lastLBA) { + if (firstLBA >= sectorCount || lastLBA >= sectorCount || firstLBA > lastLBA) { return false; } partitions[i].present = true; partitions[i].offset = firstLBA; - partitions[i].count = lastLBA - firstLBA; + partitions[i].count = lastLBA - firstLBA + 1; partitions[i].isESP = guidLow == 0x11D2F81FC12A7328 && guidHigh == 0x3BC93EC9A0004BBA; - - if (partitions[i].isESP) { - if (foundESP) { - return false; - } else { - foundESP = true; - } - } } return true;