Fix static analysis issue 78/324178/5
authorChanggyu Choi <changyu.choi@samsung.com>
Wed, 14 May 2025 00:48:06 +0000 (09:48 +0900)
committerChanggyu Choi <changyu.choi@samsung.com>
Wed, 14 May 2025 01:10:05 +0000 (10:10 +0900)
Changes:
 - Adds nullptr checking logic

Change-Id: Ice8b0e1191d3030ab203e526a953290cac79bc96
Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/modules/watchdog/src/amd_watchdog.c

index a6420a044a123d5cf234df5a8d7ad0743ebdd0ff..f0ccbb7adf97cc6d2207cd7f1b3d12f9ac9596bd 100644 (file)
@@ -32,6 +32,7 @@
 #include <bundle_internal.h>
 #include <amd.h>
 #include <signal.h>
+#include <ctype.h>
 
 #include "amd_watchdog_config.h"
 #include "amd_watchdog_logger.h"
@@ -340,7 +341,16 @@ static int __dispatch_watchdog_print_bt(amd_request_h req)
        int ret;
        tizen_core_h bt_core;
        bundle *b = amd_request_get_bundle(req);
-       int pid = atoi(bundle_get_val(b, AUL_K_TARGET_PID));
+       const char *pid_str = bundle_get_val(b, AUL_K_TARGET_PID);
+       pid_t pid;
+
+       if (pid_str == NULL || !isdigit(pid_str[0])) {
+               _E("Failed to get target pid");
+               amd_request_send_result(req, -EINVAL);
+               return -1;
+       }
+
+       pid = atoi(pid_str);
 
        _I("Print BT pid=%d", pid);
        ret = tizen_core_find("Backtrace+", &bt_core);
@@ -371,6 +381,7 @@ static int __dispatch_printbt_checker(amd_cynara_caller_info_h info,
        pid_t target_pid;
        pid_t target_pgid;
        bundle *b;
+       const char *target_pid_str;
 
        sender_uid = amd_request_get_uid(req);
        if (sender_uid < REGULAR_UID_MIN)
@@ -383,7 +394,13 @@ static int __dispatch_printbt_checker(amd_cynara_caller_info_h info,
                return AMD_CYNARA_RET_ERROR;
        }
 
-       target_pid = atoi(bundle_get_val(b, AUL_K_TARGET_PID));
+       target_pid_str = bundle_get_val(b, AUL_K_TARGET_PID);
+       if (target_pid_str == NULL || !isdigit(target_pid_str[0])) {
+               _E("Failed to get target pid");
+               return AMD_CYNARA_RET_ERROR;
+       }
+
+       target_pid = atoi(target_pid_str);
        if (target_pid == 0) {
                _E("Wrong target pid %s", bundle_get_val(b, AUL_K_TARGET_PID));
                return AMD_CYNARA_RET_ERROR;