Ensure apps in the package have unique names 93/319693/6
authorKrzysztof Malysa <k.malysa@samsung.com>
Fri, 14 Feb 2025 16:59:07 +0000 (17:59 +0100)
committerKrzysztof Małysa <k.malysa@samsung.com>
Thu, 20 Feb 2025 12:19:11 +0000 (12:19 +0000)
Change-Id: I6bf4af9657ddd37f3970148c1a3e660b510aa414

src/common/service_impl.cpp

index 6fca09028b02c2c7a3d164fe5ce6fb6ae3047baa..cb53a1bd5e637e60de582e0ad87b8575cfbf8821 100644 (file)
@@ -46,6 +46,8 @@
 #include <sys/smack.h>
 #include <unistd.h>
 #include <stdexcept>
+#include <string_view>
+#include <unordered_set>
 
 #include <dpl/log/log.h>
 #include <dpl/errno_string.h>
@@ -516,6 +518,18 @@ int ServiceImpl::appInstallInitialChecks(const Credentials &creds, app_inst_req
         return SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED;
     }
 
+    // Check that all apps have unique names
+    {
+        std::unordered_set<std::string_view> appNames;
+        for (const auto& app : req.apps) {
+            if (!appNames.emplace(app.appName).second) {
+                LogError("Found two applications with name: " << app.appName
+                    << ". Returning error.");
+                return SECURITY_MANAGER_ERROR_INPUT_PARAM;
+            }
+        }
+    }
+
     return SECURITY_MANAGER_SUCCESS;
 }