Fix crash issue
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 13 Dec 2023 10:42:05 +0000 (19:42 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 13 Dec 2023 10:48:23 +0000 (19:48 +0900)
If the byte is empty, calling std::copy() makes a crash issue.

Change-Id: Ia786bb045159a9cf81d45d5d463a5bd4ff58ff86
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/lib/launch/step_prepare_starting_app.cc

index b717bd0027b0237c008140398818938f30a5362a..79a094d384e89af9eeb3bfe5c08a80db164b2f25 100644 (file)
@@ -93,10 +93,13 @@ int FindAndSetWidgetAppStatus(LaunchContext* context) {
       app_status = _app_status_find_with_org_caller(context->GetAppId().c_str(),
           context->GetTargetUid(), context->GetCallerPid());
     } else {
+      pid_t pid = -1;
       auto byte = b.GetByte(AUL_K_TARGET_PID);
-      pid_t pid;
-      auto* p = reinterpret_cast<unsigned char*>(&pid);
-      std::copy(byte.begin(), byte.begin() + sizeof(pid), p);
+      if (byte.size() == sizeof(pid)) {
+        auto* p = reinterpret_cast<unsigned char*>(&pid);
+        std::copy(byte.begin(), byte.begin() + sizeof(pid), p);
+      }
+
       if (pid < 1) {
         _E("Invalid process ID(%d)", pid);
         return -EREJECTED;
@@ -131,10 +134,13 @@ int FindAndSetWatchAppStatus(LaunchContext* context) {
     app_status = _app_status_find_with_org_caller(context->GetAppId().c_str(),
         context->GetTargetUid(), context->GetCallerPid());
   } else {
+    pid_t pid = -1;
     auto byte = b.GetByte(AUL_K_TARGET_PID);
-    pid_t pid;
-    auto* p = reinterpret_cast<unsigned char*>(&pid);
-    std::copy(byte.begin(), byte.begin() + sizeof(pid), p);
+    if (byte.size() == sizeof(pid)) {
+      auto* p = reinterpret_cast<unsigned char*>(&pid);
+      std::copy(byte.begin(), byte.begin() + sizeof(pid), p);
+    }
+
     if (pid > 0) {
       app_status = _app_status_find(pid);
     } else {