From c7ad94e3180dc674f049b5e15f84ccdbded2ac61 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Wed, 27 Jul 2022 13:34:45 -0600 Subject: [PATCH] api.c: fix null deference in is_cgrp_ctrl_shared_mnt() Fix explicit null dereferenced warning, reported by Coverity tool: CID 258306 (#1 of 1): Explicit null dereferenced (FORWARD_NULL). var_deref_model: Passing null pointer controller_name to cgroup_find_parent, which dereferences it. the code path which leads to the null dereference: cgroup_delete_cgroup_ext() - cgroup_find_parent() - is_cgrp_ctrl_shared_mnt() is_cgrp_ctrl_shared_mnt(), assumes that the controller_name is non-NULL but there are changes that, this static function might be called with NULL controller_name, let's fix it with a check. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- src/api.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/api.c b/src/api.c index ad87a174..4f1059b5 100644 --- a/src/api.c +++ b/src/api.c @@ -2734,6 +2734,9 @@ static int is_cgrp_ctrl_shared_mnt(char *controller) int ret = 0; int i; + if (!controller) + return ret; + pthread_rwlock_rdlock(&cg_mount_table_lock); for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) { -- 2.47.2