Fix checking plugin crash issue due to plugin packaging error.

pull/4962/head
Don HO 2018-10-25 03:34:49 +02:00
parent 519fecbb82
commit ef5d07771a
2 changed files with 32 additions and 9 deletions

View File

@ -64,6 +64,9 @@ generic_string commafyInt(size_t n)
std::string getFileContent(const TCHAR *file2read)
{
if (!::PathFileExists(file2read))
return "";
const size_t blockSize = 1024;
char data[blockSize];
std::string wholeFileContent = "";
@ -72,7 +75,7 @@ std::string getFileContent(const TCHAR *file2read)
size_t lenFile = 0;
do
{
lenFile = fread(data, 1, blockSize - 1, fp);
lenFile = fread(data, 1, blockSize, fp);
if (lenFile <= 0) break;
wholeFileContent.append(data, lenFile);
}

View File

@ -505,15 +505,33 @@ DWORD WINAPI PluginsAdminDlg::launchPluginInstallerThread(void* params)
PathAppend(installedPluginPath, lwp->_pluginUpdateInfo->_folderName + TEXT(".dll"));
// check installed id to prevent from MITMA
char sha2hashStr[65] = { '\0' };
std::string content = getFileContent(installedPluginPath.c_str());
if (content.empty())
{
// Remove installed plugin
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance())->getNativeLangSpeaker();
pNativeSpeaker->messageBox("PluginBuiltWronglyCannotFound",
NULL,
TEXT("The plugin package is built wrongly. This plugin will be uninstalled."),
TEXT("Plugin cannot be found"),
MB_OK | MB_APPLMODAL,
0,
lwp->_pluginUpdateInfo->_displayName.c_str());
deleteFileOrFolder(installedPluginFolder);
return FALSE;
}
else
{
uint8_t sha2hash[32];
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
char sha2hashStr[65] = {'\0'};
for (size_t i = 0; i < 32; i++)
{
sprintf(sha2hashStr + i * 2, "%02x", sha2hash[i]);
}
}
string s = ws2s(lwp->_pluginUpdateInfo->_id);
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
if (s == sha2hashStr)
@ -544,7 +562,7 @@ DWORD WINAPI PluginsAdminDlg::launchPluginInstallerThread(void* params)
pNativeSpeaker->messageBox("PluginIdNotMatchedWillBeRemoved",
NULL,
TEXT("The plugin \"$STR_REPLACE$\" ID is not correct. This plugin will be uninstalled."),
TEXT("Plugin ID missmathed"),
TEXT("Plugin ID mismathed"),
MB_OK | MB_APPLMODAL,
0,
lwp->_pluginUpdateInfo->_displayName.c_str());
@ -786,6 +804,9 @@ PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const gen
_displayName = filename;
std::string content = getFileContent(fullFilePath.c_str());
if (content.empty())
return;
uint8_t sha2hash[32];
calc_sha_256(sha2hash, reinterpret_cast<const uint8_t*>(content.c_str()), content.length());
char sha2hashStr[65] = {'\0'};
@ -798,7 +819,6 @@ PluginUpdateInfo::PluginUpdateInfo(const generic_string& fullFilePath, const gen
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
_id = wmc->char2wchar(sha2hashStr, CP_ACP);
_version.setVersionFrom(fullFilePath);
}
typedef const char * (__cdecl * PFUNCGETPLUGINLIST)();