From 5cf24f84f31c323ad46c7a0bf7d7b162ab1a387c Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Fri, 17 Feb 2023 09:54:50 +0000 Subject: [PATCH] tools/cgset: fix Uninitialized pointers read 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 Signed-off-by: Tom Hromatka (cherry picked from commit 4611135a0672ba2bb2b275cd71e57873da4ec293) --- src/tools/cgset.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tools/cgset.c b/src/tools/cgset.c index 89a73ca7..ae3e2e33 100644 --- a/src/tools/cgset.c +++ b/src/tools/cgset.c @@ -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); -- 2.47.2