From: Unsung Lee Date: Tue, 7 Jan 2025 02:32:43 +0000 (+0900) Subject: kernel: Add an error handler to check null pointer X-Git-Tag: accepted/tizen/8.0/unified/20250108.155923^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_8.0;p=platform%2Fcore%2Fsystem%2Fpass.git kernel: Add an error handler to check null pointer 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 --- diff --git a/src/util/kernel.c b/src/util/kernel.c index 6259968..e638329 100644 --- a/src/util/kernel.c +++ b/src/util/kernel.c @@ -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);