From e34ae57b9bcb736489142acf56484dd647691f11 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Wed, 3 Aug 2022 12:36:48 -0600 Subject: [PATCH] api.c: fix dereference after null check Fix dereference after null check warning, reported by Coverity tool: CID 258308 (#1 of 1): Dereference after null check (FORWARD_NULL). var_deref_model: Passing null pointer controller to strncmp, which dereferences it. Fix the warning in cgroup_get_controller_version(), by checking for the an empty controller in the case of cgroup v1. 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 a5a98dc7..f8c5acd7 100644 --- a/src/api.c +++ b/src/api.c @@ -5862,6 +5862,9 @@ int cgroup_get_controller_version(const char * const controller, enum cg_version return 0; } + if (!controller) + return ECGINVAL; + *version = CGROUP_UNK; for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) { -- 2.47.2