44 lines
1.6 KiB
Diff
44 lines
1.6 KiB
Diff
From e44306f00bd12f4dca2db20eaba103ff2f260d87 Mon Sep 17 00:00:00 2001
|
|
From: Rod Smith <rodsmith@rodsbooks.com>
|
|
Date: Mon, 14 Sep 2020 10:08:18 -0400
|
|
Subject: [PATCH 1/2] Fix segfault on some weird data structures
|
|
|
|
---
|
|
gpt.cc | 13 ++++++++++++-
|
|
1 file changed, 12 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/gpt.cc b/gpt.cc
|
|
index 03a2156..d0242d3 100644
|
|
--- a/gpt.cc
|
|
+++ b/gpt.cc
|
|
@@ -983,6 +983,14 @@ int GPTData::LoadHeader(struct GPTHeader *header, DiskIO & disk, uint64_t sector
|
|
} // if
|
|
*crcOk = CheckHeaderCRC(&tempHeader);
|
|
|
|
+ if (tempHeader.sizeOfPartitionEntries != sizeof(GPTPart)) {
|
|
+ cerr << "Warning: Partition table header claims that the size of partition table\n";
|
|
+ cerr << "entries is " << tempHeader.sizeOfPartitionEntries << " bytes, but this program ";
|
|
+ cerr << " supports only " << sizeof(GPTPart) << "-byte entries.\n";
|
|
+ cerr << "Adjusting accordingly, but partition table may be garbage.\n";
|
|
+ tempHeader.sizeOfPartitionEntries = sizeof(GPTPart);
|
|
+ }
|
|
+
|
|
if (allOK && (numParts != tempHeader.numParts) && *crcOk) {
|
|
allOK = SetGPTSize(tempHeader.numParts, 0);
|
|
}
|
|
@@ -1000,7 +1008,10 @@ int GPTData::LoadPartitionTable(const struct GPTHeader & header, DiskIO & disk,
|
|
uint32_t sizeOfParts, newCRC;
|
|
int retval;
|
|
|
|
- if (disk.OpenForRead()) {
|
|
+ if (header.sizeOfPartitionEntries != sizeof(GPTPart)) {
|
|
+ cerr << "Error! GPT header contains invalid partition entry size!\n";
|
|
+ retval = 0;
|
|
+ } else if (disk.OpenForRead()) {
|
|
if (sector == 0) {
|
|
retval = disk.Seek(header.partitionEntriesLBA);
|
|
} else {
|
|
--
|
|
2.35.1
|
|
|