]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgxget: fix segfault in free path
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 14 Apr 2023 15:30:01 +0000 (15:30 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 17 Apr 2023 17:59:26 +0000 (11:59 -0600)
cgxget tool crashes, when passing basic operations such as multiple
cgroups as arguments or invalid parameters, it turns out the address of
struct cgroup passed for cgroup_free() has been invalid.

$ sudo ./src/tools/cgxget -1 -r cpu.shares a b
Segmentation fault (core dumped)

$ sudo ./src/tools/cgxget -1 cpu.shares a b
Segmentation fault (core dumped)

this patch fixes it by passing the right address of the struct cgroup[]
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 a1299d6cd01fbff653a3fe919a67ea86483a054e)

src/tools/cgxget.c

index 225e3a637866f601c31293fd21c7160e8f918243..a9eb0fd2bdae677b4067a2cd0a1e0b07e386969d 100644 (file)
@@ -823,7 +823,7 @@ out:
                 * Free the old list.
                 */
                for (i = 0; i < cg_list_len; i++)
-                       cgroup_free(cg_list[i]);
+                       cgroup_free(&(*cg_list)[i]);
 
                *cg_list = cg_converted_list;
        }