From: Kamalesh Babulal Date: Wed, 3 Aug 2022 18:36:48 +0000 (-0600) Subject: api.c: fix dereference after null check X-Git-Tag: v3.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e34ae57b9bcb736489142acf56484dd647691f11;p=thirdparty%2Flibcgroup.git 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 --- 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++) {