From d0add5355b434df64c5f9fb28b9ab4bdd86f93f2 Mon Sep 17 00:00:00 2001
Message-Id: <d0add5355b434df64c5f9fb28b9ab4bdd86f93f2@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:04 +0200
Subject: [PATCH] vircgroup: Duplicate string before modifying
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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>
(cherry picked from commit 4b2fb60777bdad70df2871dad1d0e604cda078c6)
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <b57526226460be172899f5a6e14f185eabb18cea.1561993099.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/util/vircgroup.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index df38bb77e0..45b854e864 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -350,18 +350,22 @@ virCgroupCopyMounts(virCgroupPtr group,
static int
-virCgroupResolveMountLink(char *mntDir,
+virCgroupResolveMountLink(const char *mntDir,
const char *typeStr,
virCgroupControllerPtr controller)
{
VIR_AUTOFREE(char *) linkSrc = NULL;
+ VIR_AUTOFREE(char *) tmp = NULL;
char *dirName;
struct stat sb;
- dirName = strrchr(mntDir, '/');
+ if (VIR_STRDUP(tmp, mntDir) < 0)
+ return -1;
+
+ dirName = strrchr(tmp, '/');
if (!dirName) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("Missing '/' separator in cgroup mount '%s'"), mntDir);
+ _("Missing '/' separator in cgroup mount '%s'"), tmp);
return -1;
}
@@ -369,14 +373,14 @@ virCgroupResolveMountLink(char *mntDir,
return 0;
*dirName = '\0';
- if (virAsprintf(&linkSrc, "%s/%s", mntDir, typeStr) < 0)
+ if (virAsprintf(&linkSrc, "%s/%s", tmp, typeStr) < 0)
return -1;
*dirName = '/';
if (lstat(linkSrc, &sb) < 0) {
if (errno == ENOENT) {
VIR_WARN("Controller %s co-mounted at %s is missing symlink at %s",
- typeStr, mntDir, linkSrc);
+ typeStr, tmp, linkSrc);
} else {
virReportSystemError(errno, _("Cannot stat %s"), linkSrc);
return -1;
--
2.22.0