[EU-FOSSA] Fix buffer overrun in Print dialog

This commit is contained in:
Don HO 2019-02-18 23:13:28 +01:00
parent 194475ce64
commit 0adc06322f
2 changed files with 25 additions and 16 deletions

View File

@ -2387,23 +2387,34 @@ INT_PTR CALLBACK PrintSettingsDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
case IDC_BUTTON_ADDVAR: case IDC_BUTTON_ADDVAR:
{ {
try {
if (!_focusedEditCtrl) if (!_focusedEditCtrl)
return TRUE; return TRUE;
auto iSel = ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETCURSEL, 0, 0); auto iSel = ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETCURSEL, 0, 0);
TCHAR *varStr = (TCHAR *)::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETITEMDATA, iSel, 0); TCHAR *varStr = (TCHAR *)::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETITEMDATA, iSel, 0);
DWORD selStart = 0;
::SendDlgItemMessage(_hSelf, _focusedEditCtrl, EM_GETSEL, reinterpret_cast<WPARAM>(&_selStart), reinterpret_cast<LPARAM>(&_selEnd)); DWORD selEnd = 0;
::SendDlgItemMessage(_hSelf, _focusedEditCtrl, EM_GETSEL, reinterpret_cast<WPARAM>(&selStart), reinterpret_cast<LPARAM>(&selEnd));
const int stringSize = 256; const int stringSize = 256;
TCHAR str[stringSize]; TCHAR str[stringSize];
::SendDlgItemMessage(_hSelf, _focusedEditCtrl, WM_GETTEXT, stringSize, reinterpret_cast<LPARAM>(str)); ::SendDlgItemMessage(_hSelf, _focusedEditCtrl, WM_GETTEXT, stringSize, reinterpret_cast<LPARAM>(str));
generic_string str2Set(str); generic_string str2Set(str);
str2Set.replace(_selStart, _selEnd - _selStart, varStr); size_t strLen = str2Set.length();
if (selStart > strLen || selEnd > strLen)
selStart = selEnd = strLen;
str2Set.replace(selStart, selEnd - selStart, varStr);
::SetDlgItemText(_hSelf, _focusedEditCtrl, str2Set.c_str()); ::SetDlgItemText(_hSelf, _focusedEditCtrl, str2Set.c_str());
} }
catch (...)
{
// Do nothing
}
}
break; break;
} }
return TRUE; return TRUE;

View File

@ -148,13 +148,11 @@ struct strCouple {
class PrintSettingsDlg : public StaticDialog class PrintSettingsDlg : public StaticDialog
{ {
public : public :
PrintSettingsDlg():_focusedEditCtrl(0), _selStart(0), _selEnd(0){}; PrintSettingsDlg(){};
private : private :
INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
std::vector<strCouple> varList; std::vector<strCouple> varList;
int _focusedEditCtrl; int _focusedEditCtrl = 0;
DWORD _selStart;
DWORD _selEnd;
}; };
class BackupDlg : public StaticDialog class BackupDlg : public StaticDialog