Anastasia Klimchuk has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/85292?usp=email )
Change subject: libflashrom: Fix comparison of layout romentry regions ......................................................................
libflashrom: Fix comparison of layout romentry regions
Comparing structs (romentries in this case) with memcmp won't work if the struct includes pointers.
Also in this case romentry region is compared to the one loaded from dump, and from dump only start, end and name are filled in.
https://ticket.coreboot.org/issues/570
Prior effort: https://review.coreboot.org/c/flashrom/+/72433
Change-Id: I715969036c8e516aac8d90b46830f1f92ae6a160 Signed-off-by: Anastasia Klimchuk aklm@flashrom.org --- M libflashrom.c 1 file changed, 10 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/92/85292/1
diff --git a/libflashrom.c b/libflashrom.c index dfc86e6..78e5c9b 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -306,6 +306,15 @@ } }
+static int compare_region_with_dump(const struct romentry *const a, const struct romentry *const b) +{ + if (a->region.start != b->region.end + || a->region.end != b->region.end + || strcmp(a->region.name, b->region.name)) + return 1; + return 0; +} + int flashrom_layout_read_from_ifd(struct flashrom_layout **const layout, struct flashctx *const flashctx, const void *const dump, const size_t len) { @@ -343,7 +352,7 @@
const struct romentry *chip_entry = layout_next(chip_layout, NULL); const struct romentry *dump_entry = layout_next(dump_layout, NULL); - while (chip_entry && dump_entry && !memcmp(chip_entry, dump_entry, sizeof(*chip_entry))) { + while (chip_entry && dump_entry && !compare_region_with_dump(chip_entry, dump_entry)) { chip_entry = layout_next(chip_layout, chip_entry); dump_entry = layout_next(dump_layout, dump_entry); }