Check user ID to reduce unnecessary IPC 55/316355/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 20 Aug 2024 05:15:56 +0000 (14:15 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 20 Aug 2024 05:15:56 +0000 (14:15 +0900)
If the user ID of the caller process is less than regular user ID,
the aul_app_get_appid_bypid() does not send the request to amd.
It's to reduce unnecessary IPC.

Change-Id: I1fa1935f3660d9ab59c21892c9ac90f0a1ad31c4
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/aul/pkginfo.cc
test/unit_tests/test_launch_with_result.cc

index dab6003bde5ed72b331fa385b735b7330414a68c..8eb4db9f3eca25b5b34fd265d4a392c8f452d553 100644 (file)
@@ -428,6 +428,11 @@ extern "C" API int aul_app_get_appid_bypid_for_uid(int pid, char* appid,
       snprintf(appid, len, "%s", preinit_appid.c_str());
       return AUL_R_OK;
     }
+
+    if (getuid() < REGULAR_UID_MIN) {
+      _E("pid(%d) is not an application", getpid());
+      return AUL_R_ERROR;
+    }
   }
 
   int fd = AppRequest(APP_GET_APPID_BYPID, uid)
@@ -469,6 +474,11 @@ extern "C" API int aul_app_get_pkgid_bypid_for_uid(int pid, char* pkgid,
       return AUL_R_OK;
     }
 
+    if (getuid() < REGULAR_UID_MIN) {
+      _E("pid(%d) is not an application", getpid());
+      return AUL_R_ERROR;
+    }
+
     if (GetPkgIdFromDB(pid, pkgid, len, uid) == 0)
       return AUL_R_OK;
   }
index 08a625be9db4c70d95f74cdf74218cdda654f113..e4af2642b0ca734ccf8e5a6b426decf87472d318 100644 (file)
@@ -370,8 +370,7 @@ TEST_F(LaunchWithResultTest, aul_set_instance_info) {
 }
 
 TEST_F(LaunchWithResultTest, aul_send_result) {
-  int cmd1 = -1;
-  int cmd2 = -1;
+  int cmd = -1;
   tizen_base::Bundle b = {
       { AUL_K_SEND_RESULT, "1" },
       { AUL_K_CALLER_PID, "100" }
@@ -380,34 +379,17 @@ TEST_F(LaunchWithResultTest, aul_send_result) {
   EXPECT_NE(pkt, nullptr);
 
   EXPECT_CALL(GetMock<SocketMock>(), send(_, _, _, _))
-      .Times(2)
-      .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
-          -> ssize_t {
-        const app_pkt_t* header = reinterpret_cast<const app_pkt_t*>(buf);
-        cmd1 = header->cmd;
-        return n;
-      }))
+      .Times(1)
       .WillOnce(Invoke([&](int fd, const void* buf, size_t n, int flags)
           -> ssize_t {
         const app_pkt_t* header = reinterpret_cast<const app_pkt_t*>(buf);
-        cmd2 = header->cmd;
-        return n;
-      }));
-  EXPECT_CALL(GetMock<SocketMock>(), recv(_, _, _, _))
-      .Times(2)
-      .WillOnce(Invoke([&](int fd, void* buf, size_t n, int flags) -> ssize_t {
-        memcpy(buf, pkt.get(), n);  // Header
-        return n;
-      }))
-      .WillOnce(Invoke([&](int fd, void* buf, size_t n, int flags) -> ssize_t {
-        memcpy(buf, pkt->data, n);  // Body
+        cmd = header->cmd;
         return n;
       }));
 
   int ret = aul_send_result(b.GetHandle(), 0);
   EXPECT_EQ(ret, AUL_R_OK);
-  EXPECT_EQ(cmd1, APP_GET_APPID_BYPID);
-  EXPECT_EQ(cmd2, APP_RESULT);
+  EXPECT_EQ(cmd, APP_RESULT);
 }
 
 TEST_F(LaunchWithResultTest, aul_add_caller_cb) {