check size before calling substr() accepted/tizen/unified/20181010.061627 submit/tizen/20181005.002000
authorWoongsuk Cho <ws77.cho@samsung.com>
Tue, 2 Oct 2018 04:31:37 +0000 (13:31 +0900)
committer조웅석/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <ws77.cho@samsung.com>
Thu, 4 Oct 2018 22:32:15 +0000 (07:32 +0900)
NativeLauncher/installer-plugin/ni_common.cc

index f9e81b8..4c5ca44 100644 (file)
@@ -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