Fix GetAppId() method 66/316066/2
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 13 Aug 2024 06:11:19 +0000 (15:11 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 13 Aug 2024 06:33:41 +0000 (15:33 +0900)
If the caller process ID is equal to the target process ID, the rpc-port
should check whether the user ID is less than the regular user ID or not.

Change-Id: Id60fc954986e871a9d7038b3253bbf212ab30b2f
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/rpc-port/aul-internal.cc
src/rpc-port/stub-internal.cc

index ec32a6cae942d7585bd9823fe62f3c7f20b077b9..4e714e8f0eeded67eabd2d5a43f335ceb6f442f9 100644 (file)
@@ -40,11 +40,11 @@ std::string Aul::GetName(int pid) {
 }
 
 std::string Aul::GetAppId(int pid) {
-  if (getuid() >= kRegularUidMin) {
-    char app_id[256] = { 0, };
-    int ret = aul_app_get_appid_bypid(pid, app_id, sizeof(app_id));
-    if (ret == AUL_R_OK) return std::string(app_id);
-  }
+  if (getpid() == pid && getuid() < kRegularUidMin) return GetName(pid);
+
+  char app_id[256] = { 0, };
+  int ret = aul_app_get_appid_bypid(pid, app_id, sizeof(app_id));
+  if (ret == AUL_R_OK) return std::string(app_id);
 
   return GetName(pid);
 }
index 68864aa79b9bee69c418077bef96be004b0cebb6..fa32935e6ea918045def797982465aed3ffe8f02 100644 (file)
@@ -304,6 +304,7 @@ void Stub::CheckPermission(const std::shared_ptr<Request>& request,
                            const std::shared_ptr<PeerCred>& cred) {
   std::string app_id;
   if (cred->GetUid() >= kRegularUidMin) app_id = Aul::GetAppId(cred->GetPid());
+
   auto response_func = [=](int res) -> void {
     if (freed_stubs_.find(this) != freed_stubs_.end())
       return;  // LCOV_EXCL_LINE