From e2f05e9ec5f830b13c3516e92087397807eae945 Mon Sep 17 00:00:00 2001 From: Unsung Lee Date: Tue, 7 Jan 2025 11:32:43 +0900 Subject: [PATCH] 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 --- src/util/kernel.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); -- 2.34.1