Unverified Commit 256928ac by Stéphane Graber Committed by GitHub

Merge pull request #3526 from brauner/2020-08-21/fixes

cgfsng: fix cgroup attach cgroup creation
parents 9d3b7c97 c80c9a70
...@@ -2216,13 +2216,21 @@ static int cgroup_attach_leaf(const struct lxc_conf *conf, int unified_fd, pid_t ...@@ -2216,13 +2216,21 @@ static int cgroup_attach_leaf(const struct lxc_conf *conf, int unified_fd, pid_t
do { do {
bool rm = false; bool rm = false;
char attach_cgroup[STRLITERALLEN(".lxc-1000/cgroup.procs") + 1]; char attach_cgroup[STRLITERALLEN(".lxc-/cgroup.procs") + INTTYPE_TO_STRLEN(int) + 1];
char *slash; char *slash;
ret = snprintf(attach_cgroup, sizeof(attach_cgroup), ".lxc-%d/cgroup.procs", idx); ret = snprintf(attach_cgroup, sizeof(attach_cgroup), ".lxc-%d/cgroup.procs", idx);
if (ret < 0 || (size_t)ret >= sizeof(attach_cgroup)) if (ret < 0 || (size_t)ret >= sizeof(attach_cgroup))
return ret_errno(EIO); return ret_errno(EIO);
/*
* This shouldn't really happen but the compiler might complain
* that a short write would cause a buffer overrun. So be on
* the safe side.
*/
if (ret < STRLITERALLEN(".lxc-/cgroup.procs"))
return log_error_errno(-EINVAL, EINVAL, "Unexpected short write would cause buffer-overrun");
slash = &attach_cgroup[ret] - STRLITERALLEN("/cgroup.procs"); slash = &attach_cgroup[ret] - STRLITERALLEN("/cgroup.procs");
*slash = '\0'; *slash = '\0';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment