Fix crash issue 81/302781/1
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:42:05 +0000 (19:42 +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 ac3143098068715ee410073a07ad6efe44ef3ec3..f9c9e5c8e20345d32cc0ee1acf348bf486023bd2 100644 (file)
@@ -106,10 +106,13 @@ int FindAndSetWidgetAppStatus(LaunchContext* context) {
           context->GetAppId(), 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;
@@ -144,10 +147,13 @@ int FindAndSetWatchAppStatus(LaunchContext* context) {
     app_status = amd::AppStatusManager::GetInst().FindWithOriginalCaller(
         context->GetAppId(), 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 = amd::AppStatusManager::GetInst().Find(pid);
     } else {