From 74a1a54892e3211fa5ffebe3f3e1a59f56f07fcc Mon Sep 17 00:00:00 2001 From: Anastasia Klimchuk Date: Mon, 25 Nov 2024 21:12:58 +1100 Subject: [PATCH] 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 Reviewed-on: https://review.coreboot.org/c/flashrom/+/85292 Reviewed-by: Peter Marheine Tested-by: build bot (Jenkins) --- libflashrom.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libflashrom.c b/libflashrom.c index dfc86e6e1..78e5c9be3 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -306,6 +306,15 @@ bool flashrom_flag_get(const struct flashrom_flashctx *const flashctx, const enu } } +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 @@ int flashrom_layout_read_from_ifd(struct flashrom_layout **const layout, struct 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); }