render / rpms / libvirt

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