From dcd8ad0dcb077cec8791f4f9d8d5eed9f4db86e3 Mon Sep 17 00:00:00 2001 From: Peter Marheine Date: Wed, 8 Mar 2023 09:27:40 +1100 Subject: fmap: ignore areas with zero size It's impossible for flashrom_layout to represent zero-sized flash regions but it is possible for a fmap to contain a zero-sized region which causes the resulting layout to fail layout_sanity_checks(), preventing use of that fmap. Because it would very rarely make sense to be able to operate on zero-sized regions anyway and changing layouts to be able to support zero-size regions would entail large changes, instead ignore zero-size regions when present in fmap. TEST=Warning is now printed when using fmap that contains a zero-sized area, and operations on other regions are allowed to proceed. BUG=b:271933192 Change-Id: Ie20971f779acece7a0b3b8f38796fff128ce689a Signed-off-by: Peter Marheine Reviewed-on: https://review.coreboot.org/c/flashrom/+/73571 Tested-by: build bot (Jenkins) Reviewed-by: Thomas Heijligen Reviewed-by: Edward O'Callaghan --- libflashrom.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libflashrom.c b/libflashrom.c index 2e89fe5a..4a59e2a1 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -362,6 +362,16 @@ static int flashrom_layout_parse_fmap(struct flashrom_layout **layout, return 1; for (i = 0, area = fmap->areas; i < fmap->nareas; i++, area++) { + if (area->size == 0) { + /* Layout regions use inclusive upper and lower bounds, + * so it's impossible to represent a region with zero + * size although it's allowed in fmap. */ + msg_gwarn("Ignoring zero-size fmap region \"%s\";" + " empty regions are unsupported.\n", + area->name); + continue; + } + snprintf(name, sizeof(name), "%s", area->name); if (flashrom_layout_add_region(l, area->offset, area->offset + area->size - 1, name)) { flashrom_layout_release(l); -- cgit v1.2.3