From 501bc43cc5a27470520ab2950865f4d060fa075e Mon Sep 17 00:00:00 2001 From: gentle_hu Date: Mon, 17 Jul 2023 20:30:54 +0800 Subject: [PATCH] Fix the issue of memory overlap when copying cgroup strings --- src/bin/gs_cgroup/cgexec.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/bin/gs_cgroup/cgexec.cpp b/src/bin/gs_cgroup/cgexec.cpp index ae85209f9..9dde56179 100644 --- a/src/bin/gs_cgroup/cgexec.cpp +++ b/src/bin/gs_cgroup/cgexec.cpp @@ -1054,9 +1054,11 @@ static int cgexec_create_remain_cgroup(gscgroup_grp_t* grp) cpushares = MAX_CLASS_CPUSHARES * cgutil_vaddr[i]->ginfo.cls.rempct / GROUP_ALL_PERCENT; ioweight = IO_WEIGHT_CALC(MAX_IO_WEIGHT, cgutil_vaddr[i]->ginfo.cls.rempct); - sret = - snprintf_s(cgutil_vaddr[i]->cpuset, CPUSET_LEN, CPUSET_LEN - 1, "%s", cgutil_vaddr[grp->ginfo.wd.cgid]->cpuset); - securec_check_intval(sret, free(relpath), -1); + if (i != grp->ginfo.wd.cgid) { + sret = snprintf_s(cgutil_vaddr[i]->cpuset, CPUSET_LEN, CPUSET_LEN - 1, + "%s", cgutil_vaddr[grp->ginfo.wd.cgid]->cpuset); + securec_check_intval(sret, free(relpath), -1); + } (void)cgexec_create_default_cgroup(relpath, cpushares, ioweight, cgutil_vaddr[i]->cpuset);