]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: fix "uninitialized transient_len" warning 3347/head
authorAleksa Sarai <cyphar@cyphar.com>
Thu, 2 Apr 2020 08:15:11 +0000 (19:15 +1100)
committerAleksa Sarai <cyphar@cyphar.com>
Thu, 2 Apr 2020 08:18:41 +0000 (19:18 +1100)
Without this change, a build error is triggered if you compile with
-Werror=maybe-uninitialized.

 cgroups/cgfsng.c: In function 'cgfsng_monitor_enter':
 groups/cgfsng.c:1387:9: error: 'transient_len' may be used uninitialized in this function
    ret = lxc_writeat(h->cgfd_mon, "cgroup.procs", transient, transient_len);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The issue is that if handler->transient_pid is 0, then transient_len is
uninitialised but lxc_writeat(..., transient_len) still gets called.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
src/lxc/cgroups/cgfsng.c

index 564400221faedd324ede1c2079e4e8777eef38d0..21c2c3f7cec59093bb10432a508f9adbcee8f026 100644 (file)
@@ -1388,7 +1388,7 @@ __cgfsng_ops static bool cgfsng_monitor_enter(struct cgroup_ops *ops,
                if (ret)
                        return log_error_errno(false, errno, "Failed to enter cgroup \"%s\"", h->monitor_full_path);
 
-                if (handler->transient_pid < 0)
+               if (handler->transient_pid <= 0)
                        return true;
 
                ret = lxc_writeat(h->cgfd_mon, "cgroup.procs", transient, transient_len);