]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgset: fix Uninitialized pointers read
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 17 Feb 2023 09:54:50 +0000 (09:54 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 17 Feb 2023 15:13:58 +0000 (08:13 -0700)
Fix Uninitialized pointer read, reported by Coverity Tool:

CID 307778 (#2 of 2): Uninitialized pointer read (UNINIT)22.
uninit_use_in_call: Using uninitialized value src_cgroup when calling
cgroup_free.

In main(), src_cgrp points to a valid struct cgroup only when the user
calls cgset using --copy-from flag, Coverity warns about the freeing
src_cgrp, which is uninitialized in the error path.  This patch
initializes src_cgrp and cgroup uninitialized pointers and checks
is src_cgrp is valid pointer before passing it to cgroup_free()

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 4611135a0672ba2bb2b275cd71e57873da4ec293)

src/tools/cgset.c

index 89a73ca7698c807ceac5c650ca2abe78a2e35b56..ae3e2e3339b0fc9aea392afa1ea937ea79db0cac 100644 (file)
@@ -131,8 +131,8 @@ int main(int argc, char *argv[])
        int nv_max = 0;
 
        char src_cg_path[FILENAME_MAX] = "\0";
-       struct cgroup *src_cgroup;
-       struct cgroup *cgroup;
+       struct cgroup *src_cgroup = NULL;
+       struct cgroup *cgroup = NULL;
 
        int ret = 0;
        int c;
@@ -271,7 +271,8 @@ int main(int argc, char *argv[])
 cgroup_free_err:
        if (cgroup)
                cgroup_free(&cgroup);
-       cgroup_free(&src_cgroup);
+       if (src_cgroup)
+               cgroup_free(&src_cgroup);
 err:
        free(name_value);