From 0c78a27d9fbcb0b1dfa8cd28fec1ebf9de20f6d3 Mon Sep 17 00:00:00 2001 From: Rik Smeets <30838294+rik-smeets@users.noreply.github.com> Date: Tue, 11 Oct 2022 13:27:11 +0200 Subject: [PATCH] Fix missing validation on invalid characters in file name (#18287) When saving a new file with a name containing '/' or '\' on Windows, the incorrect file name would be determined since these characters represent a new folder. This would trigger a failure on save. The user's input should be validated in all cases. Before, it was only executed for folder names. This change also applies the validation on file names. --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/LoadSave.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 1332d4c83b..28496a6a98 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,6 +1,7 @@ 0.4.3 (in development) ------------------------------------------------------------------------ - Fix: [#14312] Research ride type message incorrect. +- Fix: [#17763] Missing validation on invalid characters in file name. - Fix: [#17853] Invention name tears while being dragged. - Fix: [#18064] Unable to dismiss notification messages. - Fix: [#18070] Underground entrance/exit shows through terrain walls (original bug). diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 94e85d3375..7830778331 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -575,16 +575,16 @@ static void WindowLoadsaveTextinput(rct_window* w, WidgetIndex widgetIndex, char if (text == nullptr || text[0] == 0) return; + if (!Platform::IsFilenameValid(text)) + { + context_show_error(STR_ERROR_INVALID_CHARACTERS, STR_NONE, {}); + return; + } + switch (widgetIndex) { case WIDX_NEW_FOLDER: { - if (!Platform::IsFilenameValid(text)) - { - context_show_error(STR_ERROR_INVALID_CHARACTERS, STR_NONE, {}); - return; - } - const u8string path = Path::Combine(_directory, text); if (!Platform::EnsureDirectoryExists(path)) {