vircgroup: Duplicate string before modifying

The 'mntDir' is part of 'struct mntent' as a result of getmntent_r
therefore we should not mangle with it.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2018-08-15 15:59:08 +02:00
parent 0fa11dc0c9
commit 4b2fb60777

View File

@ -350,18 +350,22 @@ virCgroupCopyMounts(virCgroupPtr group,
static int static int
virCgroupResolveMountLink(char *mntDir, virCgroupResolveMountLink(const char *mntDir,
const char *typeStr, const char *typeStr,
virCgroupControllerPtr controller) virCgroupControllerPtr controller)
{ {
VIR_AUTOFREE(char *) linkSrc = NULL; VIR_AUTOFREE(char *) linkSrc = NULL;
VIR_AUTOFREE(char *) tmp = NULL;
char *dirName; char *dirName;
struct stat sb; struct stat sb;
dirName = strrchr(mntDir, '/'); if (VIR_STRDUP(tmp, mntDir) < 0)
return -1;
dirName = strrchr(tmp, '/');
if (!dirName) { if (!dirName) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Missing '/' separator in cgroup mount '%s'"), mntDir); _("Missing '/' separator in cgroup mount '%s'"), tmp);
return -1; return -1;
} }
@ -369,14 +373,14 @@ virCgroupResolveMountLink(char *mntDir,
return 0; return 0;
*dirName = '\0'; *dirName = '\0';
if (virAsprintf(&linkSrc, "%s/%s", mntDir, typeStr) < 0) if (virAsprintf(&linkSrc, "%s/%s", tmp, typeStr) < 0)
return -1; return -1;
*dirName = '/'; *dirName = '/';
if (lstat(linkSrc, &sb) < 0) { if (lstat(linkSrc, &sb) < 0) {
if (errno == ENOENT) { if (errno == ENOENT) {
VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s", VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s",
typeStr, mntDir, linkSrc); typeStr, tmp, linkSrc);
} else { } else {
virReportSystemError(errno, _("Cannot stat %s"), linkSrc); virReportSystemError(errno, _("Cannot stat %s"), linkSrc);
return -1; return -1;