Fix static analysis issue 98/318598/7
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 21 Jan 2025 03:59:10 +0000 (12:59 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Wed, 22 Jan 2025 03:35:49 +0000 (12:35 +0900)
Changes:
 - Add group nullptr checking.
 - Add destroying main task.
 - Fix request manager to return false when fail to create socket ready file
 - Fix RequestManager::Fini to unlink socket ready file
 - Replace filesystem::exists() method with access().
 - Add missing target include directory

Change-Id: If870e9edcdf4886f0fc78390a754d3cef404c671
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/lib/CMakeLists.txt
src/lib/amd_main.cc
src/lib/app_com/app_com_broker.cc
src/lib/request/request_manager.cc
src/modules/ui-core/src/app_group.c

index 280c92bdf033a0b348ad4ccaad2d08c0eb436ff7..83315a3d063a2b083bfcae82ff5f01e57a5d005d 100644 (file)
@@ -67,9 +67,10 @@ SET_TARGET_PROPERTIES(${TARGET_LIB_AMD} PROPERTIES COMPILE_FLAGS
 SET_TARGET_PROPERTIES(${TARGET_LIB_AMD} PROPERTIES LINK_FLAGS "-ldl -lpthread")
 
 TARGET_INCLUDE_DIRECTORIES(${TARGET_LIB_AMD} PUBLIC
-  ${CMAKE_CURRENT_SOURCE_DIR}/api)
-TARGET_INCLUDE_DIRECTORIES(${TARGET_LIB_AMD} PUBLIC
-  ${CMAKE_CURRENT_SOURCE_DIR}/../)
+  ${CMAKE_CURRENT_SOURCE_DIR}
+  ${CMAKE_CURRENT_SOURCE_DIR}/../
+  ${CMAKE_CURRENT_SOURCE_DIR}/api
+)
 
 APPLY_PKG_CONFIG(${TARGET_LIB_AMD} PUBLIC
   AUL_DEPS
index 1ec6ca379c484ddbe4120bc7610b4d8ddfc285bb..1eeee5ef6f89183047a097d825b6d874e1c746d0 100644 (file)
@@ -328,18 +328,19 @@ extern "C" EXPORT int amd_main(int argc, char** argv) {
         return G_SOURCE_REMOVE;
       }, nullptr);
 
-  tizen_core_h core = nullptr;
-  int ret = tizen_core_task_create("main", false, &core);
+  tizen_core_task_h task = nullptr;
+  int ret = tizen_core_task_create("main", false, &task);
   if (ret != TIZEN_CORE_ERROR_NONE) {
     _E("tizen_core_task_create() is failed. error(%d)", ret);
     return -1;
   }
 
   _W("AMD_LOOP_START");
-  tizen_core_task_run(core);
+  tizen_core_task_run(task);
   _W("AMD_LOOP_END");
   Finalize();
 
+  tizen_core_task_destroy(task);
   tizen_core_shutdown();
   return 0;
 }
index 067f6543caa928a2c0dc9dda8a93274357f971a3..3f59c7993ea357ffbabb81a192f55979628f9022 100644 (file)
@@ -300,9 +300,8 @@ std::shared_ptr<AppComSocket> AppComBroker::CreateAppComSocket(pid_t pid,
   try {
     auto app_com_socket = std::make_shared<AppComSocket>(pid, uid, this);
     std::string endpoint = GetEndpoint(pid, uid);
-    std::filesystem::path path(endpoint);
-    if (!std::filesystem::exists(path)) {
-      _E("pid(%d) app com endpoint does not exists.", pid);
+    if (access(endpoint.c_str(), F_OK) != 0) {
+      _E("pid(%d) app com endpoint does not exists. errno(%d)", pid, errno);
       return nullptr;
     }
 
index 78649ff6037c6cad401ea783e70e92b15d844fe3..e61ddbd3860471c3eb74884e7675104c6f099d38 100644 (file)
@@ -36,6 +36,8 @@
 namespace amd {
 namespace {
 
+constexpr const char kAmdSockReady[] = "/run/aul/daemons/.amd-sock";
+
 bool IsTerminationRequest(int cmd) {
   if (cmd == APP_TERM_BY_PID ||
       cmd == APP_TERM_REQ_BY_PID ||
@@ -564,6 +566,11 @@ bool RequestManager::Init() {
   // TODO(Abstract Socket Issue): file-based socket check
   marker = open(kAmdSockReady, O_RDWR | O_CREAT,
       S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
+  if(marker < 0) {
+    _E("Fail to create ready file (%s)", kAmdSockReady);
+    Fini();
+    return false;
+  }
   close(marker);
 
   amd_io_ = g_io_channel_unix_new(amd_fd_);
@@ -584,6 +591,8 @@ bool RequestManager::Init() {
 }
 
 void RequestManager::Fini() {
+  unlink(kAmdSockReady);
+
   if (amd_wid_) {
     g_source_remove(amd_wid_);
     amd_wid_ = 0;
index b4a14d63cde84ec3b871ad5bdf4713315e765282..9429d6050eed3ce0faefbb7acce9c679985b4717 100644 (file)
@@ -492,6 +492,11 @@ app_group_node_h _app_group_node_add_node(app_group_node_h node)
 
        ctx = (struct app_group_context_s *)node->data;
        group = _app_group_find(ctx->id);
+       if (!group) {
+               _E("Failed to find app group. %s", ctx->id);
+               return NULL;
+       }
+
        new_ctx = __create_app_group_context(ctx->pid, ctx->id, ctx->caller_pid,
                        ctx->caller_id, ctx->launch_mode, ctx->can_shift, true);
        if (!new_ctx) {
@@ -504,7 +509,6 @@ app_group_node_h _app_group_node_add_node(app_group_node_h node)
        new_ctx->reroute = true;
        new_ctx->can_be_leader = ctx->can_be_leader;
 
-       group = _app_group_find(ctx->id);
        group->list = g_list_append(group->list, new_ctx);
 
        return g_list_last(group->list);