]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: block copy: Forbid block copy to relative paths
authorPeter Krempa <pkrempa@redhat.com>
Fri, 16 Dec 2016 17:30:39 +0000 (18:30 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 16 Dec 2016 17:30:39 +0000 (18:30 +0100)
Similarly to 29bb066915 forbid paths used with blockjobs to be relative.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1300177

src/conf/snapshot_conf.c
src/libvirt_private.syms
src/qemu/qemu_driver.c
src/util/virstoragefile.c
src/util/virstoragefile.h

index 862c2ec00ea579faab4b6e09ac75158229f515ac..5daa8d11a7353440d6a4727c205fa13047ef2cf7 100644 (file)
@@ -170,9 +170,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node,
     }
 
     /* validate that the passed path is absolute */
-    if (virStorageSourceIsLocalStorage(def->src) &&
-        def->src->path &&
-        def->src->path[0] != '/') {
+    if (virStorageSourceIsRelative(def->src)) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("disk snapshot image path '%s' must be absolute"),
                        def->src->path);
index 7beebbf27b5a909a4c4b79f875ba9214368c6b08..5c82e4a0e67413e98cf74d55d534c7a0dfecec30 100644 (file)
@@ -2455,6 +2455,7 @@ virStorageSourceInitChainElement;
 virStorageSourceIsBlockLocal;
 virStorageSourceIsEmpty;
 virStorageSourceIsLocalStorage;
+virStorageSourceIsRelative;
 virStorageSourceNewFromBacking;
 virStorageSourceNewFromBackingAbsolute;
 virStorageSourceParseRBDColonString;
index 0bf18564466f52c4012e3fc091f2cd602fbd1f94..1a464337e88c0bc8b95c1338fdf015bc6421c3c0 100644 (file)
@@ -16665,6 +16665,12 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
     priv = vm->privateData;
     cfg = virQEMUDriverGetConfig(driver);
 
+    if (virStorageSourceIsRelative(mirror)) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("absolute path must be used as block copy target"));
+        goto cleanup;
+    }
+
     if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0)
         goto cleanup;
 
index 9ec005d5004908b3817f708491a0a8bd50d33a2d..ce6d21388a7752b687908cff6491d2cf715484d6 100644 (file)
@@ -3672,3 +3672,34 @@ virStorageFileCheckCompat(const char *compat)
     virStringListFree(version);
     return ret;
 }
+
+
+/**
+ * virStorageSourceIsRelative:
+ * @src: storage source to check
+ *
+ * Returns true if given storage source definition is a relative path.
+ */
+bool
+virStorageSourceIsRelative(virStorageSourcePtr src)
+{
+    virStorageType actual_type = virStorageSourceGetActualType(src);
+
+    if (!src->path)
+        return false;
+
+    switch (actual_type) {
+    case VIR_STORAGE_TYPE_FILE:
+    case VIR_STORAGE_TYPE_BLOCK:
+    case VIR_STORAGE_TYPE_DIR:
+        return src->path[0] != '/';
+
+    case VIR_STORAGE_TYPE_NETWORK:
+    case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
+    case VIR_STORAGE_TYPE_LAST:
+        return false;
+    }
+
+    return false;
+}
index 6d1aac78dfb03ac423765414a630d6bbd88b4a5b..1f62244dbcbc7b839cbecf8a925b65132d7e2c5f 100644 (file)
@@ -388,4 +388,6 @@ int virStorageFileCheckCompat(const char *compat);
 
 virStorageSourcePtr virStorageSourceNewFromBackingAbsolute(const char *path);
 
+bool virStorageSourceIsRelative(virStorageSourcePtr src);
+
 #endif /* __VIR_STORAGE_FILE_H__ */