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

View File

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