From d81f236910c04449fb5162d5221684eb9d34b8b1 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Tue, 23 Mar 2021 23:35:27 +0000 Subject: [PATCH] gsdx:windows: Handle shader dialog filenames properly The shader dialog filename handling code had several buffer overflows and also did not handle non-English filenames well. Fix the filename handling by storing them as UTF-8 in the ini and converting them to/from UTF-16 as necessary, and also fix the buffer overflows. --- plugins/GSdx/Window/GSSettingsDlg.cpp | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/plugins/GSdx/Window/GSSettingsDlg.cpp b/plugins/GSdx/Window/GSSettingsDlg.cpp index 554d1d84ec..e80cae8b7f 100644 --- a/plugins/GSdx/Window/GSSettingsDlg.cpp +++ b/plugins/GSdx/Window/GSSettingsDlg.cpp @@ -27,8 +27,6 @@ #include "resource.h" #include "GSSetting.h" #include -#include -#include GSSettingsDlg::GSSettingsDlg() : GSDialog(IDD_CONFIG) @@ -397,12 +395,10 @@ void GSShaderDlg::OnInit() // External FX shader CheckDlgButton(m_hWnd, IDC_SHADER_FX, theApp.GetConfigB("shaderfx")); - std::string tmp = theApp.GetConfigS("shaderfx_glsl"); - std::wstring wsTmp(tmp.begin(), tmp.end()); - SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_EDIT), WM_SETTEXT, 0, (LPARAM)wsTmp.c_str()); - tmp = theApp.GetConfigS("shaderfx_conf"); - wsTmp = std::wstring(tmp.begin(), tmp.end()); - SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_CONF_EDIT), WM_SETTEXT, 0, (LPARAM)wsTmp.c_str()); + std::wstring filename = convert_utf8_to_utf16(theApp.GetConfigS("shaderfx_glsl")); + SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_EDIT), WM_SETTEXT, 0, (LPARAM)filename.c_str()); + filename = convert_utf8_to_utf16(theApp.GetConfigS("shaderfx_conf")); + SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_CONF_EDIT), WM_SETTEXT, 0, (LPARAM)filename.c_str()); // FXAA shader CheckDlgButton(m_hWnd, IDC_FXAA, theApp.GetConfigB("fxaa")); @@ -525,15 +521,14 @@ bool GSShaderDlg::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) const int shader_fx_length = (int)SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_EDIT), WM_GETTEXTLENGTH, 0, 0); const int shader_fx_conf_length = (int)SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_CONF_EDIT), WM_GETTEXTLENGTH, 0, 0); const int length = std::max(shader_fx_length, shader_fx_conf_length) + 1; - std::unique_ptr buffer(new char[length]); - char* output = new char[length]; + std::unique_ptr buffer = std::make_unique(length); SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_EDIT), WM_GETTEXT, (WPARAM)length, (LPARAM)buffer.get()); - wcstombs(output, (wchar_t*)buffer.get(), length); - theApp.SetConfig("shaderfx_glsl", output); // Not really glsl only ;) + std::string output = convert_utf16_to_utf8(buffer.get()); + theApp.SetConfig("shaderfx_glsl", output.c_str()); // Not really glsl only ;) SendMessage(GetDlgItem(m_hWnd, IDC_SHADER_FX_CONF_EDIT), WM_GETTEXT, (WPARAM)length, (LPARAM)buffer.get()); - wcstombs(output, (wchar_t*)buffer.get(), length); - theApp.SetConfig("shaderfx_conf", output); + output = convert_utf16_to_utf8(buffer.get()); + theApp.SetConfig("shaderfx_conf", output.c_str()); EndDialog(m_hWnd, id); } break;