From 4ca1aa5931de40d2849b2f1369eaaf51c6fd02f5 Mon Sep 17 00:00:00 2001 From: Andrew Jeffery Date: Fri, 2 Mar 2018 12:08:29 +1030 Subject: pnor_partition_table: Disallow overlapping partitions Change-Id: I25c6a6c4cee69ce9ba28c238851c7b7c622bb9b3 Signed-off-by: Andrew Jeffery --- pnor_partition_table.cpp | 25 +++++++++++++++++++++++++ test/vpnor/Makefile.am.include | 2 -- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pnor_partition_table.cpp b/pnor_partition_table.cpp index 67b32f1..c9d56a2 100644 --- a/pnor_partition_table.cpp +++ b/pnor_partition_table.cpp @@ -99,6 +99,31 @@ void Table::preparePartitions() parseTocLine(line, blockSize, part); + if (numParts > 0) + { + struct pnor_partition& prev = table.partitions[numParts - 1]; + uint32_t prev_end = prev.data.base + prev.data.size; + + if (part.data.id == prev.data.id) + { + MSG_ERR("ID for previous partition '%s' at block 0x%" PRIx32 + "matches current partition '%s' at block 0x%" PRIx32 + ": %" PRId32 "\n", + prev.data.name, prev.data.base, part.data.name, + part.data.base, part.data.id); + } + + if (part.data.base < prev_end) + { + std::stringstream err; + err << "Partition '" << part.data.name << "' start block 0x" + << std::hex << part.data.base << "is less than the end " + << "block 0x" << std::hex << prev_end << " of '" + << prev.data.name << "'"; + throw InvalidTocEntry(err.str()); + } + } + file = directory / part.data.name; if (!fs::exists(file)) { diff --git a/test/vpnor/Makefile.am.include b/test/vpnor/Makefile.am.include index 6765b02..831b146 100644 --- a/test/vpnor/Makefile.am.include +++ b/test/vpnor/Makefile.am.include @@ -137,6 +137,4 @@ check_PROGRAMS += \ %reldir%/toc_no_version \ %reldir%/toc_flags \ %reldir%/toc_overlap - -XFAIL_TESTS += %reldir%/toc_overlap endif -- cgit v1.2.1