]> 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:39:09 +0000 (12:39 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 3 Aug 2022 18:39:33 +0000 (12:39 -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>
(cherry picked from commit e34ae57b9bcb736489142acf56484dd647691f11)

src/api.c

index e2eba8c2af7ab69dae9a21d8e0bdb33d1f21ecb7..280eebf743e05f7dbbbaec86ff5c3428a8342275 100644 (file)
--- 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++) {