From 7c1f6c82a6bf7ea49c5b9566f0b3e62efac24602 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 9 Apr 2015 18:10:23 +0000 Subject: potentially unsafe string operation removed git-svn-id: http://svn.miranda-ng.org/main/trunk@12714 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/stdfile/src/commonheaders.h | 1 + src/core/stdfile/src/fileopts.cpp | 31 +++++++++++++------------------ 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/core/stdfile/src/commonheaders.h b/src/core/stdfile/src/commonheaders.h index f0de6fd8be..78fd70be3d 100644 --- a/src/core/stdfile/src/commonheaders.h +++ b/src/core/stdfile/src/commonheaders.h @@ -76,6 +76,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include #include "version.h" diff --git a/src/core/stdfile/src/fileopts.cpp b/src/core/stdfile/src/fileopts.cpp index 899eb224a6..ad8c3560b9 100644 --- a/src/core/stdfile/src/fileopts.cpp +++ b/src/core/stdfile/src/fileopts.cpp @@ -155,36 +155,31 @@ static INT_PTR CALLBACK DlgProcFileOpts(HWND hwndDlg, UINT msg, WPARAM wParam, L break; case IDC_SCANCMDLINE: - if (HIWORD(wParam) == CBN_SELCHANGE) PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); - else if (HIWORD(wParam) != CBN_EDITCHANGE) return 0; + if (HIWORD(wParam) == CBN_SELCHANGE) + PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); + else if (HIWORD(wParam) != CBN_EDITCHANGE) + return 0; break; case IDC_SCANCMDLINEBROWSE: TCHAR str[MAX_PATH + 2]; - OPENFILENAME ofn = { 0 }; - TCHAR filter[512], *pfilter; - GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); + + CMString tszFilter; + tszFilter.AppendFormat(_T("%s (*.exe)%c*.exe%c"), TranslateT("Executable files"), 0, 0); + tszFilter.AppendFormat(_T("%s (*)%c*%c"), TranslateT("All files"), 0, 0); + + OPENFILENAME ofn = { 0 }; ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; ofn.hwndOwner = hwndDlg; ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_DONTADDTORECENT; - _tcscpy(filter, TranslateT("Executable files")); - _tcscat(filter, _T(" (*.exe)")); - pfilter = filter + _tcslen(filter) + 1; - _tcscpy(pfilter, _T("*.exe")); - pfilter = pfilter + _tcslen(pfilter) + 1; - _tcscpy(pfilter, TranslateT("All files")); - _tcscat(pfilter, _T(" (*)")); - pfilter = pfilter + _tcslen(pfilter) + 1; - _tcscpy(pfilter, _T("*")); - pfilter = pfilter + _tcslen(pfilter) + 1; - *pfilter = 0; - ofn.lpstrFilter = filter; + ofn.lpstrFilter = tszFilter; ofn.lpstrFile = str; ofn.nMaxFile = SIZEOF(str) - 2; if (str[0] == '"') { TCHAR *pszQuote = _tcschr(str + 1, '"'); - if (pszQuote) *pszQuote = 0; + if (pszQuote) + *pszQuote = 0; memmove(str, str + 1, (_tcslen(str) * sizeof(TCHAR))); } else { -- cgit v1.2.3