From c086a3386f844e9e62df8fde22d27459dd66d541 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sun, 28 Nov 2021 14:36:49 +0000 Subject: x1000-installer: map filenames accept only valid characters Instead of using isgraph(), check for legal FAT32 characters excluding spaces (which are used as field separators). Change-Id: I291f0acb5f24c558099c237d913f4f35ae06b834 --- lib/x1000-installer/src/xf_flashmap.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/x1000-installer/src/xf_flashmap.c b/lib/x1000-installer/src/xf_flashmap.c index 2cde0f1c20..dc0a26a019 100644 --- a/lib/x1000-installer/src/xf_flashmap.c +++ b/lib/x1000-installer/src/xf_flashmap.c @@ -37,6 +37,18 @@ static int xdigit_to_int(char c) return -1; } +static int isfilenamechar(char c) +{ + return (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9') || + c == '$' || c == '%' || c == '\'' || c == '-' || c == '_' || + c == '@' || c == '~' || c == '`' || c == '!' || c == '(' || + c == ')' || c == '{' || c == '}' || c == '^' || c == '#' || + c == '&' || c == '+' || c == ',' || c == ';' || c == '=' || + c == '[' || c == ']' || c == '.'; +} + int xf_map_parseline(const char* line, struct xf_map* map) { enum { @@ -66,7 +78,7 @@ int xf_map_parseline(const char* line, struct xf_map* map) if(*line == ' ' || *line == '\t') { nextstate(); continue; - } else if(isgraph((unsigned char)*line)) { + } else if(isfilenamechar(*line)) { if(length == XF_MAP_NAMELEN) return XF_E_FILENAME_TOO_LONG; -- cgit v1.2.3