render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c401cc
From 8a557289017d7549bebf00164214bf377761dabc Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <8a557289017d7549bebf00164214bf377761dabc@dist-git>
c401cc
From: "Daniel P. Berrange" <berrange@redhat.com>
c401cc
Date: Tue, 18 Feb 2014 15:45:37 -0700
c401cc
Subject: [PATCH] Add virFileMakeParentPath helper function
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1045643
c401cc
prereq of CVE-2013-6456
c401cc
c401cc
Add a helper function which takes a file path and ensures
c401cc
that all directory components leading up to the file exist.
c401cc
IOW, it strips the filename part of the path and passes
c401cc
the result to virFileMakePath.
c401cc
c401cc
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
c401cc
(cherry picked from commit c321bfc5c37c603af349dacf531bb03c91b0755e)
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/libvirt_private.syms |  1 +
c401cc
 src/util/virfile.c       | 29 +++++++++++++++++++++++++++++
c401cc
 src/util/virfile.h       |  1 +
c401cc
 3 files changed, 31 insertions(+)
c401cc
c401cc
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c401cc
index 852affa..e5f80e1 100644
c401cc
--- a/src/libvirt_private.syms
c401cc
+++ b/src/libvirt_private.syms
c401cc
@@ -1393,6 +1393,7 @@ virFileIsMountPoint;
c401cc
 virFileLinkPointsTo;
c401cc
 virFileLock;
c401cc
 virFileLoopDeviceAssociate;
c401cc
+virFileMakeParentPath;
c401cc
 virFileMakePath;
c401cc
 virFileMakePathWithMode;
c401cc
 virFileMatchesNameSuffix;
c401cc
diff --git a/src/util/virfile.c b/src/util/virfile.c
c401cc
index 0d4a6be..defcc3f 100644
c401cc
--- a/src/util/virfile.c
c401cc
+++ b/src/util/virfile.c
c401cc
@@ -2262,6 +2262,35 @@ cleanup:
c401cc
     return ret;
c401cc
 }
c401cc
 
c401cc
+
c401cc
+int
c401cc
+virFileMakeParentPath(const char *path)
c401cc
+{
c401cc
+    char *p;
c401cc
+    char *tmp;
c401cc
+    int ret = -1;
c401cc
+
c401cc
+    VIR_DEBUG("path=%s", path);
c401cc
+
c401cc
+    if (VIR_STRDUP(tmp, path) < 0) {
c401cc
+        errno = ENOMEM;
c401cc
+        return -1;
c401cc
+    }
c401cc
+
c401cc
+    if ((p = strrchr(tmp, '/')) == NULL) {
c401cc
+        errno = EINVAL;
c401cc
+        goto cleanup;
c401cc
+    }
c401cc
+    *p = '\0';
c401cc
+
c401cc
+    ret = virFileMakePathHelper(tmp, 0777);
c401cc
+
c401cc
+ cleanup:
c401cc
+    VIR_FREE(tmp);
c401cc
+    return ret;
c401cc
+}
c401cc
+
c401cc
+
c401cc
 /* Build up a fully qualified path for a config file to be
c401cc
  * associated with a persistent guest or network */
c401cc
 char *
c401cc
diff --git a/src/util/virfile.h b/src/util/virfile.h
c401cc
index 0d20cdb..20baf6f 100644
c401cc
--- a/src/util/virfile.h
c401cc
+++ b/src/util/virfile.h
c401cc
@@ -198,6 +198,7 @@ int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
c401cc
 int virFileMakePath(const char *path) ATTRIBUTE_RETURN_CHECK;
c401cc
 int virFileMakePathWithMode(const char *path,
c401cc
                             mode_t mode) ATTRIBUTE_RETURN_CHECK;
c401cc
+int virFileMakeParentPath(const char *path) ATTRIBUTE_RETURN_CHECK;
c401cc
 
c401cc
 char *virFileBuildPath(const char *dir,
c401cc
                        const char *name,
c401cc
-- 
c401cc
1.9.0
c401cc