]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: Duplicate string before modifying
authorPavel Hrdina <phrdina@redhat.com>
Wed, 15 Aug 2018 13:59:08 +0000 (15:59 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 27 Aug 2018 15:39:19 +0000 (17:39 +0200)
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>
src/util/vircgroup.c

index df38bb77e05d3110f27e3f29697b793933d7c8ec..45b854e864e1f08fa73422213af0331f5e454493 100644 (file)
@@ -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;