Anastasia Klimchuk submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Peter Marheine: Looks good to me, approved
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>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/85292
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
---
M libflashrom.c
1 file changed, 10 insertions(+), 1 deletion(-)

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);
}

To view, visit change 85292. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: flashrom
Gerrit-Branch: main
Gerrit-Change-Id: I715969036c8e516aac8d90b46830f1f92ae6a160
Gerrit-Change-Number: 85292
Gerrit-PatchSet: 2
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Peter Marheine <pmarheine@chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>