From: Kamalesh Babulal Date: Wed, 3 Aug 2022 18:39:09 +0000 (-0600) Subject: api.c: fix dereference after null check X-Git-Tag: v2.0.3~23 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9426c2f548efbf3b41a5fdf2618614bd0c21dd9;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 (cherry picked from commit e34ae57b9bcb736489142acf56484dd647691f11) --- diff --git a/src/api.c b/src/api.c index e2eba8c2..280eebf7 100644 --- a/src/api.c +++ b/src/api.c @@ -5806,6 +5806,9 @@ int cgroup_get_controller_version(const char * const controller, if (!version) return ECGINVAL; + if (!controller) + return ECGINVAL; + *version = CGROUP_UNK; for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) {