From ef5d07771aa68282be5434b677a54365730a1152 Mon Sep 17 00:00:00 2001 From: Don HO Date: Thu, 25 Oct 2018 03:34:49 +0200 Subject: [PATCH] Fix checking plugin crash issue due to plugin packaging error. --- PowerEditor/src/MISC/Common/Common.cpp | 5 ++- .../WinControls/PluginsAdmin/pluginsAdmin.cpp | 36 ++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 7912b0bc3..eb097d97b 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -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); } diff --git a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp index 4dc19dc92..cd7e96a3a 100644 --- a/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp +++ b/PowerEditor/src/WinControls/PluginsAdmin/pluginsAdmin.cpp @@ -505,14 +505,32 @@ 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()); - uint8_t sha2hash[32]; - calc_sha_256(sha2hash, reinterpret_cast(content.c_str()), content.length()); - char sha2hashStr[65] = {'\0'}; - - for (size_t i = 0; i < 32; i++) + if (content.empty()) { - sprintf(sha2hashStr + i*2, "%02x", sha2hash[i]); + // 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(content.c_str()), content.length()); + + 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); @@ -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(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)();