From 1e2dd075888a7e79b89496ad0cb92d8a59d1163a Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Fri, 4 Aug 2023 19:12:35 +0300 Subject: [PATCH] Fix hardfile2/filesys2 escaping --- cfgfile.cpp | 120 ++++++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/cfgfile.cpp b/cfgfile.cpp index af30b7d4..55d91af9 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -372,33 +372,6 @@ static const TCHAR *obsolete[] = { #define UNEXPANDED _T("$(FILE_PATH)") -static void clearmountitems(struct uae_prefs *p) -{ - p->mountitems = 0; - for (int i = 0; i < MOUNT_CONFIG_SIZE; i++) { - p->mountconfig[i].configoffset = -1; - p->mountconfig[i].unitnum = -1; - } -} - -void discard_prefs(struct uae_prefs *p, int type) -{ - struct strlist **ps = &p->all_lines; - while (*ps) { - struct strlist *s = *ps; - *ps = s->next; - xfree(s->value); - xfree(s->option); - xfree(s); - } - p->all_lines = NULL; - currprefs.all_lines = changed_prefs.all_lines = NULL; -#ifdef FILESYS - filesys_cleanup(); -#endif - clearmountitems(p); -} - static TCHAR *cfgfile_unescape(const TCHAR *s, const TCHAR **endpos, TCHAR separator, bool min) { bool quoted = false; @@ -425,28 +398,27 @@ static TCHAR *cfgfile_unescape(const TCHAR *s, const TCHAR **endpos, TCHAR separ c = s[i + 1]; switch (c) { - case 'X': - case 'x': - c2 = _totupper(s[i + 2]); - v = ((c2 >= 'A') ? c2 - 'A' : c2 - '0') << 4; - c2 = _totupper(s[i + 3]); - v |= (c2 >= 'A') ? c2 - 'A' : c2 - '0'; - *p++ = c2; - i += 2; - break; - case 'r': - *p++ = '\r'; - break; - case '\n': - *p++ = '\n'; - break; - default: - *p++ = c; - break; + case 'X': + case 'x': + c2 = _totupper(s[i + 2]); + v = ((c2 >= 'A') ? c2 - 'A' : c2 - '0') << 4; + c2 = _totupper(s[i + 3]); + v |= (c2 >= 'A') ? c2 - 'A' : c2 - '0'; + *p++ = c2; + i += 2; + break; + case 'r': + *p++ = '\r'; + break; + case 'n': + *p++ = '\n'; + break; + default: + *p++ = c; + break; } i++; - } - else { + } else { *p++ = c; } } @@ -464,6 +436,33 @@ static TCHAR *cfgfile_unescape_min(const TCHAR *s) return cfgfile_unescape(s, NULL, 0, true); } +static void clearmountitems(struct uae_prefs *p) +{ + p->mountitems = 0; + for (int i = 0; i < MOUNT_CONFIG_SIZE; i++) { + p->mountconfig[i].configoffset = -1; + p->mountconfig[i].unitnum = -1; + } +} + +void discard_prefs(struct uae_prefs *p, int type) +{ + struct strlist **ps = &p->all_lines; + while (*ps) { + struct strlist *s = *ps; + *ps = s->next; + xfree(s->value); + xfree(s->option); + xfree(s); + } + p->all_lines = NULL; + currprefs.all_lines = changed_prefs.all_lines = NULL; +#ifdef FILESYS + filesys_cleanup(); +#endif + clearmountitems(p); +} + static TCHAR *cfgfile_option_find_it(const TCHAR *s, const TCHAR *option, bool checkequals) { TCHAR buf[MAX_DPATH]; @@ -5240,7 +5239,7 @@ static int cfgfile_parse_newfilesys (struct uae_prefs *p, int nr, int type, TCHA // quoted special case if (tmpp2[0] == '\"') { const TCHAR *end; - TCHAR *n = cfgfile_unescape (tmpp2, &end, 0, false); + TCHAR *n = cfgfile_unescape (tmpp2, &end, 0, true); if (!n) goto invalid_fs; _tcscpy (uci.rootdir, n); @@ -5268,7 +5267,7 @@ static int cfgfile_parse_newfilesys (struct uae_prefs *p, int nr, int type, TCHA // quoted special case if (tmpp2[0] == '\"') { const TCHAR *end; - TCHAR *n = cfgfile_unescape (tmpp2, &end, 0, false); + TCHAR *n = cfgfile_unescape (tmpp2, &end, 0, true); if (!n) goto invalid_fs; _tcscpy (uci.rootdir, n); @@ -7100,18 +7099,21 @@ static int cfgfile_load_2 (struct uae_prefs *p, const TCHAR *filename, bool real } if (s) { s++; - bool quoted = false; if (s[0] == '"') { - s++; - quoted = true; - } - const TCHAR *se = _tcschr(s, quoted ? '"' : ','); - if (se) { - tmp[se - tmp] = 0; - _tcscpy(p->mountconfig[0].ci.rootdir, s); - cfgfile_resolve_path_load(p->mountconfig[0].ci.rootdir, MAX_DPATH, isvsys ? PATH_DIR : PATH_HDF); - p->mountitems = 1; + const TCHAR *end; + TCHAR *n = cfgfile_unescape(s, &end, 0, true); + _tcscpy(tmp, n); + s = tmp; + xfree(n); + } else { + const TCHAR *se = _tcschr(s, ','); + if (se) { + tmp[se - tmp] = 0; + } } + _tcscpy(p->mountconfig[0].ci.rootdir, s); + cfgfile_resolve_path_load(p->mountconfig[0].ci.rootdir, MAX_DPATH, isvsys ? PATH_DIR : PATH_HDF); + p->mountitems = 1; } } } -- 2.47.3