1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 22:52:34 +02:00

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>
This commit is contained in:
Anastasia Klimchuk 2024-11-25 21:12:58 +11:00
parent d07d619cb9
commit 74a1a54892

View File

@ -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, int flashrom_layout_read_from_ifd(struct flashrom_layout **const layout, struct flashctx *const flashctx,
const void *const dump, const size_t len) 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 *chip_entry = layout_next(chip_layout, NULL);
const struct romentry *dump_entry = layout_next(dump_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); chip_entry = layout_next(chip_layout, chip_entry);
dump_entry = layout_next(dump_layout, dump_entry); dump_entry = layout_next(dump_layout, dump_entry);
} }