Fixed svace (376818, 386676, 386690)
authorj-h.choi <j-h.choi@samsung.com>
Mon, 5 Aug 2019 06:09:15 +0000 (15:09 +0900)
committer이형주/Common Platform Lab(SR)/Staff Engineer/삼성전자 <leee.lee@samsung.com>
Mon, 5 Aug 2019 09:52:32 +0000 (18:52 +0900)
NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc
NativeLauncher/installer-plugin/prefer_nuget_cache_plugin.cc
NativeLauncher/tool/tac_common.cc

index 470468e..91204f5 100644 (file)
@@ -77,27 +77,32 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                                _ERR("Failed to get UID");
                                return 0;
                        }
-                       for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
-                               std::string symPath = symlinkAssembly.path().string();
-                               if (!isNativeImage(symPath)) {
-                                       std::string originPath = bf::read_symlink(symPath).string();
-                                       std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
-                                       if (!bf::exists(originNiPath)) {
-                                               if(createNiDll(originPath, false) != NI_ERROR_NONE) {
-                                                       _ERR("Failed to create NI file [%s]", originPath.c_str());
-                                                       return -1;
+                       try {
+                               for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
+                                       std::string symPath = symlinkAssembly.path().string();
+                                       if (!isNativeImage(symPath)) {
+                                               std::string originPath = bf::read_symlink(symPath).string();
+                                               std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
+                                               if (!bf::exists(originNiPath)) {
+                                                       if(createNiDll(originPath, false) != NI_ERROR_NONE) {
+                                                               _ERR("Failed to create NI file [%s]", originPath.c_str());
+                                                               return -1;
+                                                       }
                                                }
-                                       }
-                                       std::string setNiPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
-                                       if (!bf::exists(setNiPath)) {
-                                               bf::create_symlink(originNiPath, setNiPath);
-                                               _INFO("%s symbolic link file generated successfully.", setNiPath.c_str());
-                                               if (lchown(setNiPath.c_str(), uid, 0)) {
-                                                       _ERR("Failed to change owner of: %s", setNiPath.c_str());
-                                                       return -1;
+                                               std::string setNiPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
+                                               if (!bf::exists(setNiPath)) {
+                                                       bf::create_symlink(originNiPath, setNiPath);
+                                                       _INFO("%s symbolic link file generated successfully.", setNiPath.c_str());
+                                                       if (lchown(setNiPath.c_str(), uid, 0)) {
+                                                               _ERR("Failed to change owner of: %s", setNiPath.c_str());
+                                                               return -1;
+                                                       }
                                                }
                                        }
                                }
+                       } catch (const bf::filesystem_error& error) {
+                               _ERR("Failed to recursive directory: %s", error.what());
+                               return -1;
                        }
                }
        }
index 1f817f0..433766f 100644 (file)
@@ -141,7 +141,7 @@ void SHA256(std::string path, char outputBuffer[65])
        }
        SHA256_Final(hash, &sha256);
        for (int i = 0; i < SHA256_DIGEST_LENGTH; i++) {
-               sprintf(outputBuffer + (i * 2), "%02x", hash[i]);
+               snprintf(outputBuffer + (i * 2), 3, "%02x", hash[i]);
        }
        outputBuffer[64] = 0;
 
@@ -589,28 +589,33 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_REMOVED(const char *pkgId, const char *app
 void cleanStep(std::string tac)
 {
        std::string current_tac = concatPath(__TAC_DIR, tac.substr(0, tac.find('/')));
-       for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
-               std::string bck_path = bck.path().string();
-               if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
-                       if (!removeAll(bck_path)) {
-                               _ERR("Failed to remove of %s", bck_path.c_str());
+       try {
+               for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
+                       std::string bck_path = bck.path().string();
+                       if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
+                               if (!removeAll(bck_path)) {
+                                       _ERR("Failed to remove of %s", bck_path.c_str());
+                               }
+                               break;
                        }
-                       break;
                }
-       }
 
-       bool isExist = false;
-       for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
-               std::string bck_path = bck.path().string();
-               if (bf::exists(bck_path) && bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") == NULL) {
-                       isExist = true;
-                       break;
+               bool isExist = false;
+               for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
+                       std::string bck_path = bck.path().string();
+                       if (bf::exists(bck_path) && bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") == NULL) {
+                               isExist = true;
+                               break;
+                       }
                }
-       }
-       if (!isExist) {
-               if (!removeAll(current_tac)) {
-                       _ERR("Failed to remove of %s", current_tac.c_str());
+               if (!isExist) {
+                       if (!removeAll(current_tac)) {
+                               _ERR("Failed to remove of %s", current_tac.c_str());
+                       }
                }
+       } catch (const bf::filesystem_error& error) {
+               _ERR("Failed to recursive directory: %s", error.what());
+               return;
        }
 }
 
@@ -658,14 +663,19 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_CLEAN(const char *pkgId, const char *appId
 void undoStep(std::string tac)
 {
        std::string current_tac = concatPath(__TAC_DIR, tac.substr(0, tac.find('/')));
-       for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
-               std::string bck_path = bck.path().string();
-               if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
-                       if (!moveFile(bck_path, bck_path.substr(0, bck_path.rfind(".bck")))) {
-                               _ERR("Failed to move %s", bck_path.c_str());
+       try {
+               for (auto& bck : bf::recursive_directory_iterator(current_tac)) {
+                       std::string bck_path = bck.path().string();
+                       if (bf::is_directory(bck_path) && strstr(bck_path.c_str(), ".bck") != NULL) {
+                               if (!moveFile(bck_path, bck_path.substr(0, bck_path.rfind(".bck")))) {
+                                       _ERR("Failed to move %s", bck_path.c_str());
+                               }
+                               break;
                        }
-                       break;
                }
+       } catch (const bf::filesystem_error& error) {
+               _ERR("Failed to recursive directory: %s", error.what());
+               return;
        }
 }
 
index 1f9c76b..78c20cf 100644 (file)
@@ -42,29 +42,34 @@ std::vector<std::string> restoreNuget;
 void cleanupDirectory()
 {
        std::vector<std::string> removeNuget;
-       for (auto& nuget : bf::recursive_directory_iterator(__TAC_DIR)) {
-               bool isExist = false;
-               std::string nugetPath = nuget.path().string();
-               for (auto& restore : restoreNuget) {
-                       if (!bf::is_directory(nugetPath)) {
-                               isExist = true;
+       try {
+               for (auto& nuget : bf::recursive_directory_iterator(__TAC_DIR)) {
+                       bool isExist = false;
+                       std::string nugetPath = nuget.path().string();
+                       for (auto& restore : restoreNuget) {
+                               if (!bf::is_directory(nugetPath)) {
+                                       isExist = true;
+                               }
+                               if (strstr(nugetPath.c_str(), restore.c_str()) != NULL) {
+                                       isExist = true;
+                                       break;
+                               }
                        }
-                       if (strstr(nugetPath.c_str(), restore.c_str()) != NULL) {
-                               isExist = true;
-                               break;
+                       if (!isExist) {
+                               removeNuget.push_back(nugetPath);
                        }
                }
-               if (!isExist) {
-                       removeNuget.push_back(nugetPath);
-               }
-       }
 
-       for (auto& rm : removeNuget) {
-               if (!removeAll(rm)) {
-                       _ERR("Failed to remove of %s", rm.c_str());
+               for (auto& rm : removeNuget) {
+                       if (!removeAll(rm)) {
+                               _ERR("Failed to remove of %s", rm.c_str());
+                       }
                }
+               removeNuget.clear();
+       } catch (const bf::filesystem_error& error) {
+               _ERR("Failed to recursive directory: %s", error.what());
+               return;
        }
-       removeNuget.clear();
 }
 
 // callback function of "pkgmgrinfo_appinfo_metadata_filter_foreach"
@@ -206,22 +211,27 @@ tac_error_e resetTACPackage(const std::string& pkgId)
        std::string binDir = concatPath(pkgRoot, "bin");
        std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
        if (bf::exists(tacDir)) {
-               for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
-                       std::string symPath = symlinkAssembly.path().string();
-                       if (bf::is_symlink(symPath)) {
-                               if (isNativeImage(symPath)) {
-                                       tacNativeImage.push_back(symPath);
+               try {
+                       for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
+                               std::string symPath = symlinkAssembly.path().string();
+                               if (bf::is_symlink(symPath)) {
+                                       if (isNativeImage(symPath)) {
+                                               tacNativeImage.push_back(symPath);
+                                       }
                                }
                        }
-               }
-               for (auto& path : tacNativeImage) {
-                       if (!removeFile(path)) {
-                               fprintf(stderr, "Failed to remove of %s", path.c_str());
-                               return TAC_ERROR_UNKNOWN;
+                       for (auto& path : tacNativeImage) {
+                               if (!removeFile(path)) {
+                                       fprintf(stderr, "Failed to remove of %s", path.c_str());
+                                       return TAC_ERROR_UNKNOWN;
+                               }
                        }
+                       tacNativeImage.clear();
+               } catch (const bf::filesystem_error& error) {
+                       _ERR("Failed to recursive directory: %s", error.what());
+                       return TAC_ERROR_UNKNOWN;
                }
        }
-       tacNativeImage.clear();
        return TAC_ERROR_NONE;
 }
 
@@ -236,32 +246,37 @@ tac_error_e createTACPackage(const std::string& pkgId)
        std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
        std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
        if (bf::exists(tacDir)) {
-               for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
-                       std::string symPath = symlinkAssembly.path().string();
-                       if (bf::is_symlink(symPath)) {
-                               if (!isNativeImage(symPath)) {
-                                       std::string originPath = bf::read_symlink(symPath).string();
-                                       std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
-                                       if (!bf::exists(originNiPath)) {
-                                               if(createNiDll(originPath, false) != NI_ERROR_NONE) {
-                                                       fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
-                                                       return TAC_ERROR_UNKNOWN;
+               try {
+                       for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
+                               std::string symPath = symlinkAssembly.path().string();
+                               if (bf::is_symlink(symPath)) {
+                                       if (!isNativeImage(symPath)) {
+                                               std::string originPath = bf::read_symlink(symPath).string();
+                                               std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
+                                               if (!bf::exists(originNiPath)) {
+                                                       if(createNiDll(originPath, false) != NI_ERROR_NONE) {
+                                                               fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
+                                                               return TAC_ERROR_UNKNOWN;
+                                                       }
                                                }
-                                       }
-                                       std::string symNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
-                                       if (!bf::exists(symNIPath)) {
-                                               bf::create_symlink(originNiPath, symNIPath);
-                                               fprintf(stderr, "%s symbolic link file generated successfully.\n", symNIPath.c_str());
-                                               updateAssemblyInfo(tacDir.c_str(), symNIPath.c_str(), true);
-
-                                               std::string NIFileName = symNIPath.substr(symNIPath.rfind('/') + 1);
-                                               if (!removeFile(concatPath(binNIDir, NIFileName))) {
-                                                       fprintf(stderr, "Failed to remove of %s\n", concatPath(binNIDir, NIFileName).c_str());
-                                                       return TAC_ERROR_UNKNOWN;
+                                               std::string symNIPath = symPath.substr(0, symPath.rfind(".dll")) + ".ni.dll";
+                                               if (!bf::exists(symNIPath)) {
+                                                       bf::create_symlink(originNiPath, symNIPath);
+                                                       fprintf(stderr, "%s symbolic link file generated successfully.\n", symNIPath.c_str());
+                                                       updateAssemblyInfo(tacDir.c_str(), symNIPath.c_str(), true);
+
+                                                       std::string NIFileName = symNIPath.substr(symNIPath.rfind('/') + 1);
+                                                       if (!removeFile(concatPath(binNIDir, NIFileName))) {
+                                                               fprintf(stderr, "Failed to remove of %s\n", concatPath(binNIDir, NIFileName).c_str());
+                                                               return TAC_ERROR_UNKNOWN;
+                                                       }
                                                }
                                        }
                                }
                        }
+               } catch (const bf::filesystem_error& error) {
+                       _ERR("Failed to recursive directory: %s", error.what());
+                       return TAC_ERROR_UNKNOWN;
                }
        }
        return TAC_ERROR_NONE;
@@ -297,31 +312,38 @@ tac_error_e disableTACPackage(const std::string& pkgId)
        std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
        std::string binNIDir = concatPath(binDir, APP_NI_SUB_DIR);
        if (bf::exists(tacDir)) {
-               for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
-                       std::string symPath = symlinkAssembly.path().string();
-                       std::string fileName = symlinkAssembly.path().filename().string();
-                       if (bf::is_symlink(symPath)) {
-                               std::string originPath = bf::read_symlink(symPath).string();
-                               if (!isNativeImage(symPath)) {
-                                       if (!copyFile(originPath, concatPath(binDir, fileName))) {
-                                               fprintf(stderr, "Failed to copy of %s\n", concatPath(binDir, fileName).c_str());
-                                               return TAC_ERROR_UNKNOWN;
-                                       }
-                                       updateAssemblyInfo(binDir.c_str(), concatPath(binDir, fileName).c_str());
-                               } else {
-                                       if (!copyFile(originPath, concatPath(binNIDir, fileName))) {
-                                               fprintf(stderr, "Failed to copy of %s\n", concatPath(binNIDir, fileName).c_str());
-                                               return TAC_ERROR_UNKNOWN;
+               try {
+                       for (auto& symlinkAssembly : bf::recursive_directory_iterator(tacDir)) {
+                               std::string symPath = symlinkAssembly.path().string();
+                               std::string fileName = symlinkAssembly.path().filename().string();
+                               if (bf::is_symlink(symPath)) {
+                                       std::string originPath = bf::read_symlink(symPath).string();
+                                       if (!isNativeImage(symPath)) {
+                                               std::string dllPath = concatPath(binDir, fileName);
+                                               if (!copyFile(originPath, dllPath)) {
+                                                       fprintf(stderr, "Failed to copy of %s\n", dllPath.c_str());
+                                                       return TAC_ERROR_UNKNOWN;
+                                               }
+                                               updateAssemblyInfo(binDir.c_str(), concatPath(binDir, fileName).c_str());
+                                       } else {
+                                               std::string niPath = concatPath(binNIDir, fileName);
+                                               if (!copyFile(originPath, niPath)) {
+                                                       fprintf(stderr, "Failed to copy of %s\n", niPath.c_str());
+                                                       return TAC_ERROR_UNKNOWN;
+                                               }
+                                               updateAssemblyInfo(binDir.c_str(), niPath.c_str());
                                        }
-                                       updateAssemblyInfo(binDir.c_str(), concatPath(binNIDir, fileName).c_str());
                                }
                        }
+                       if (!removeAll(tacDir)) {
+                               fprintf(stderr, "Failed to remove of %s\n", tacDir.c_str());
+                               return TAC_ERROR_UNKNOWN;
+                       }
+               } catch (const bf::filesystem_error& error) {
+                       _ERR("Failed to recursive directory: %s", error.what());
+                       return TAC_ERROR_UNKNOWN;
                }
        }
-       if (!removeAll(tacDir)) {
-               fprintf(stderr, "Failed to remove of %s\n", tacDir.c_str());
-               return TAC_ERROR_UNKNOWN;
-       }
        return TAC_ERROR_NONE;
 }