From a97c44caf48c343af242c04beae4f38b132fcc64 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 18 Nov 2023 15:25:21 +0200 Subject: [PATCH] Fix hardfile2 geometry file parsing, replace unsafe characters in autogenerated geometry file name --- cfgfile.cpp | 4 ++-- include/fsdb.h | 1 + od-win32/fsdb_mywin32.cpp | 1 - od-win32/fsdb_win32.cpp | 26 +++++++++++++++++--------- od-win32/hardfile_win32.cpp | 2 ++ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/cfgfile.cpp b/cfgfile.cpp index 4896ef3f..40df0b42 100644 --- a/cfgfile.cpp +++ b/cfgfile.cpp @@ -5317,14 +5317,14 @@ static int cfgfile_parse_newfilesys (struct uae_prefs *p, int nr, int type, TCHA if (getintval2 (&tmpp2, &uci.highcyl, ',', false)) { getintval (&tmpp2, &uci.pcyls, '/'); getintval (&tmpp2, &uci.pheads, '/'); - getintval2 (&tmpp2, &uci.psecs, '/', true); + getintval2 (&tmpp2, &uci.psecs, ',', true); if (uci.pheads && uci.psecs) { uci.physical_geometry = true; } else { uci.pheads = uci.psecs = uci.pcyls = 0; uci.physical_geometry = false; } - if (tmpp2[0]) { + if (tmpp2 && tmpp2[0]) { if (tmpp2[0] == '\"') { n = cfgfile_unescape (tmpp2, &end, 0, false); if (!n) diff --git a/include/fsdb.h b/include/fsdb.h index 5fe8f729..a5a037ca 100644 --- a/include/fsdb.h +++ b/include/fsdb.h @@ -184,6 +184,7 @@ extern int my_issamevolume(const TCHAR *path1, const TCHAR *path2, TCHAR *path); extern bool my_issamepath(const TCHAR *path1, const TCHAR *path2); extern bool my_createsoftlink(const TCHAR *path, const TCHAR *target); extern bool my_createshortcut(const TCHAR *source, const TCHAR *target, const TCHAR *description); +extern void makesafefilename(TCHAR*, bool); extern a_inode *custom_fsdb_lookup_aino_aname (a_inode *base, const TCHAR *aname); extern a_inode *custom_fsdb_lookup_aino_nname (a_inode *base, const TCHAR *nname); diff --git a/od-win32/fsdb_mywin32.cpp b/od-win32/fsdb_mywin32.cpp index 9d2eb2dd..8043c55c 100644 --- a/od-win32/fsdb_mywin32.cpp +++ b/od-win32/fsdb_mywin32.cpp @@ -1054,4 +1054,3 @@ const TCHAR *my_getfilepart(const TCHAR *filename) return p + 1; return filename; } - diff --git a/od-win32/fsdb_win32.cpp b/od-win32/fsdb_win32.cpp index bc8b298d..491dda1e 100644 --- a/od-win32/fsdb_win32.cpp +++ b/od-win32/fsdb_win32.cpp @@ -51,6 +51,22 @@ static TCHAR evilchars[NUM_EVILCHARS] = { '\\', '*', '?', '\"', '<', '>', '|' }; * 1632 */ +void makesafefilename(TCHAR *s, bool evilonly) +{ + TCHAR *c; + + for (int i = 0; i < NUM_EVILCHARS; i++) + while ((c = _tcschr(s, evilchars[i])) != 0) + *c = '_'; + + if (!evilonly) { + while ((c = _tcschr(s, '.')) != 0) + *c = '_'; + while ((c = _tcschr(s, ' ')) != 0) + *c = '_'; + } +} + static TCHAR *make_uaefsdbpath (const TCHAR *dir, const TCHAR *name) { size_t len; @@ -602,21 +618,13 @@ int fsdb_mode_representable_p (const a_inode *aino, int amigaos_mode) TCHAR *fsdb_create_unique_nname (a_inode *base, const TCHAR *suggestion) { - TCHAR *c; TCHAR tmp[256] = UAEFSDB_BEGINS; int i; _tcsncat (tmp, suggestion, 240); /* replace the evil ones... */ - for (i = 0; i < NUM_EVILCHARS; i++) - while ((c = _tcschr (tmp, evilchars[i])) != 0) - *c = '_'; - - while ((c = _tcschr (tmp, '.')) != 0) - *c = '_'; - while ((c = _tcschr (tmp, ' ')) != 0) - *c = '_'; + makesafefilename(tmp, false); for (;;) { TCHAR *p = build_nname (base->nname, tmp); diff --git a/od-win32/hardfile_win32.cpp b/od-win32/hardfile_win32.cpp index 7aea3555..0eaf877e 100644 --- a/od-win32/hardfile_win32.cpp +++ b/od-win32/hardfile_win32.cpp @@ -19,6 +19,7 @@ #include "memory.h" #include "autoconf.h" #include "rommgr.h" +#include "fsdb.h" #define hfd_log write_log #define hfd_log2 @@ -1662,6 +1663,7 @@ doout: _stprintf(geometry_file + _tcslen(geometry_file), _T(" %llX"), udi->size); if (geometry_file[0]) _tcscat(geometry_file, _T(".geo")); + makesafefilename(geometry_file, true); stringboxdialogactive = 1; hdini = ini; -- 2.47.3