kernel: Add an error handler to check null pointer 04/317704/1 accepted/tizen_8.0_unified tizen_8.0 accepted/tizen/8.0/unified/20250108.155923
authorUnsung Lee <unsung.lee@samsung.com>
Tue, 7 Jan 2025 02:32:43 +0000 (11:32 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 7 Jan 2025 02:33:39 +0000 (11:33 +0900)
Add an error handler of nl_cb_alloc() to check whether the return value
is null or not. This is because nl_cb_get() does not check input argument.
Therefore, null argument of nl_cb_get() can cause segmentation fault.

Change-Id: I5379ef01fcf25e967235eadb6caa200dfc8b166f
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/util/kernel.c

index 6259968b231ca30aeb270aaf53b4e3766cc4cf0c..e6383296648a547d86b6778a4b974e5ceee86884 100644 (file)
@@ -343,7 +343,11 @@ int kernel_get_process_taskstats(struct taskstats *stats, int cmd_type, pid_t pi
        if (ret < 0)
                goto err_genl_close;
 
-       cb = nl_cb_get(nl_cb_alloc(NL_CB_CUSTOM));
+       cb = nl_cb_alloc(NL_CB_CUSTOM);
+       if (!cb)
+               return -ENOMEM;
+
+       cb = nl_cb_get(cb);
        nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, &parse_task_stats, stats);
        nl_cb_err(cb, NL_CB_CUSTOM, &print_receive_error, NULL);