From 4b5e1f5102321d72859c2648aea630d32174680b Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Tue, 2 Oct 2018 13:31:37 +0900 Subject: [PATCH] check size before calling substr() --- NativeLauncher/installer-plugin/ni_common.cc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/NativeLauncher/installer-plugin/ni_common.cc b/NativeLauncher/installer-plugin/ni_common.cc index f9e81b8..4c5ca44 100644 --- a/NativeLauncher/installer-plugin/ni_common.cc +++ b/NativeLauncher/installer-plugin/ni_common.cc @@ -71,20 +71,19 @@ static void waitInterval() static bool niExist(const std::string& path, std::string& ni) { - static std::string possibleExts[] = { - ".ni.dll", ".NI.dll", ".NI.DLL", ".ni.DLL", - ".ni.exe", ".NI.exe", ".NI.EXE", ".ni.EXE" - }; - std::string fName = path.substr(0, path.size() - 4); - - struct stat sb; - - for (std::string ext : possibleExts) { - std::string f = fName + ext; - if (stat(f.c_str(), &sb) == 0) { - ni = f; - return true; - } + size_t index = path.find_last_of("."); + if (index == std::string::npos) { + return false; + } + std::string fName = path.substr(0, index); + std::string fExt = path.substr(index, path.length()); + + // crossgen generate file with lower case extension only + std::transform(fExt.begin(), fExt.end(), fExt.begin(), ::tolower); + std::string f = fName + ".ni" + fExt; + if (isFileExist(f)) { + ni = f; + return true; } // native image of System.Private.CoreLib.dll should have to overwrite -- 2.7.4