From: Woongsuk Cho Date: Tue, 2 Oct 2018 04:31:37 +0000 (+0900) Subject: check size before calling substr() X-Git-Tag: accepted/tizen/unified/20181010.061627^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4b5e1f5102321d72859c2648aea630d32174680b;p=platform%2Fcore%2Fdotnet%2Flauncher.git check size before calling substr() --- 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