From f3c21c6439f8bbd2911f120c55f301982ecd35bc Mon Sep 17 00:00:00 2001 From: Edward O'Callaghan Date: Fri, 10 Feb 2023 15:41:19 +1100 Subject: layout.c: Ensure filename is always consistent in layout structure Ensure construction and extraction filenames are symmetrical consistently within the layout structure. Change-Id: I9a0c3130c0e7d88a8a69fd29362c338e20d2bae8 Signed-off-by: Edward O'Callaghan Reviewed-on: https://review.coreboot.org/c/flashrom/+/72943 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer Reviewed-by: Anastasia Klimchuk --- layout.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'layout.c') diff --git a/layout.c b/layout.c index 4f02be699..2d7747e74 100644 --- a/layout.c +++ b/layout.c @@ -194,6 +194,15 @@ error: return 1; } +static char *sanitise_filename(char *filename) +{ + for (unsigned i = 0; filename[i]; i++) { + if (isspace((unsigned char)filename[i])) + filename[i] = '_'; + } + return filename; +} + /* returns 0 to indicate success, 1 to indicate failure */ static int include_region(struct flashrom_layout *const l, const char *name, const char *file) @@ -202,7 +211,7 @@ static int include_region(struct flashrom_layout *const l, const char *name, if (entry) { entry->included = true; if (file) - entry->file = strdup(file); + entry->file = sanitise_filename(strdup(file)); return 0; } return 1; @@ -342,18 +351,12 @@ void prepare_layout_for_extraction(struct flashctx *flash) { const struct flashrom_layout *const l = get_layout(flash); struct romentry *entry = NULL; - unsigned int i; while ((entry = mutable_layout_next(l, entry))) { entry->included = true; if (!entry->file) - entry->file = strdup(entry->region.name); - - for (i = 0; entry->file[i]; ++i) { - if (isspace((unsigned char)entry->file[i])) - entry->file[i] = '_'; - } + entry->file = sanitise_filename(strdup(entry->region.name)); } } -- cgit v1.2.3