Fixed svace (376818, 386676, 386690)
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / prefer_nuget_cache_plugin.cc
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;
        }
 }