]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: fix dereference after null check
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 3 Aug 2022 18:36:48 +0000 (12:36 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 3 Aug 2022 18:36:52 +0000 (12:36 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index a5a98dc7944e1a938af5030efcf61981ab55abba..f8c5acd7a7363495d2730bc506c09d27730e73ac 100644 (file)
--- 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++) {