diff options
author | Edward O'Callaghan <quasisec@google.com> | 2023-02-10 15:41:19 +1100 |
---|---|---|
committer | Anastasia Klimchuk <aklm@chromium.org> | 2023-04-13 09:46:03 +0000 |
commit | f3c21c6439f8bbd2911f120c55f301982ecd35bc (patch) | |
tree | b7d59571053444f966b5ab7d18b50f697742b36a /layout.c | |
parent | 6537d40e31519f7c066a6dd3835ea86569cafce7 (diff) | |
download | flashrom-git-f3c21c6439f8bbd2911f120c55f301982ecd35bc.tar.gz |
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>
Diffstat (limited to 'layout.c')
-rw-r--r-- | layout.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -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)); } } |