Anastasia Klimchuk has submitted this change. ( https://review.coreboot.org/c/flashrom/+/72943 )
Change subject: layout.c: Ensure filename is always consistent in layout structure ......................................................................
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 quasisec@google.com Reviewed-on: https://review.coreboot.org/c/flashrom/+/72943 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Stefan Reinauer stefan.reinauer@coreboot.org Reviewed-by: Anastasia Klimchuk aklm@chromium.org --- M layout.c 1 file changed, 28 insertions(+), 8 deletions(-)
Approvals: build bot (Jenkins): Verified Stefan Reinauer: Looks good to me, approved Anastasia Klimchuk: Looks good to me, approved
diff --git a/layout.c b/layout.c index 4f02be6..2d7747e 100644 --- a/layout.c +++ b/layout.c @@ -194,6 +194,15 @@ 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 @@ 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 @@ { 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)); } }