[libvirt] [PATCH 1/7] vircgroup: Duplicate string before modifying

Pavel Hrdina phrdina at redhat.com
Fri Aug 24 13:45:51 UTC 2018


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

Signed-off-by: Pavel Hrdina <phrdina at 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.17.1




More information about the libvir-list mailing list