[EU-FOSSA] Fix crash issue due to heap overflow in clipboardHistoryPanel.cpp

When the amount of clipboard data is too important, it makes crash of function WideCharToMultiByte (win32 API).
The remedy is to capture this error to prevent Notepad++ from crash.
This commit is contained in:
Don HO 2019-01-17 13:56:41 +01:00
parent 694415f8af
commit 5b1f530204

View File

@ -248,10 +248,11 @@ INT_PTR CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam,
codepage = SC_CP_UTF8;
ByteArray ba(_clipboardDataVector[i]);
char* c = nullptr;
try {
int nbChar = WideCharToMultiByte(codepage, 0, (wchar_t *)ba.getPointer(), static_cast<int32_t>(ba.getLength()), NULL, 0, NULL, NULL);
char *c = new char[nbChar+1];
c = new char[nbChar + 1];
WideCharToMultiByte(codepage, 0, (wchar_t *)ba.getPointer(), static_cast<int32_t>(ba.getLength()), c, nbChar + 1, NULL, NULL);
(*_ppEditView)->execute(SCI_REPLACESEL, 0, reinterpret_cast<LPARAM>(""));
@ -259,6 +260,13 @@ INT_PTR CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam,
(*_ppEditView)->getFocus();
delete[] c;
}
catch (...)
{
MessageBox(_hSelf, TEXT("Cannot process this clipboard data in the history:\nThe data is too large to be treated."), TEXT("Clipboard problem"), MB_OK | MB_APPLMODAL);
if (c)
delete[] c;
}
}
}
return TRUE;
}