]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuDomainCreateDevice: Be more careful about device path
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 4 Jan 2017 13:24:16 +0000 (14:24 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 4 Jan 2017 14:36:42 +0000 (15:36 +0100)
Again, not something that I'd hit, but there is a chance in
theory that this might bite us. Currently the way we decide
whether or not to create /dev entry for a device is by marching
first four characters of path with "/dev". This might be not
enough. Just imagine somebody has a disk image stored under
"/devil/path/to/disk". We ought to be matching against "/dev/".

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_domain.c

index 4eff2ef4609fa6de1e146f0949a32b093b86c476..67e8836f3bfb722aae2921843659c3f7907b3dd1 100644 (file)
@@ -6917,6 +6917,8 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev,
 }
 
 
+#define DEVPREFIX "/dev/"
+
 #if defined(__linux__)
 static int
 qemuDomainCreateDevice(const char *device,
@@ -6927,7 +6929,7 @@ qemuDomainCreateDevice(const char *device,
     struct stat sb;
     int ret = -1;
 
-    if (!STRPREFIX(device, "/dev")) {
+    if (!STRPREFIX(device, DEVPREFIX)) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("invalid device: %s"),
                        device);
@@ -6935,7 +6937,7 @@ qemuDomainCreateDevice(const char *device,
     }
 
     if (virAsprintf(&devicePath, "%s/%s",
-                    path, device + 4) < 0)
+                    path, device + strlen(DEVPREFIX)) < 0)
         goto cleanup;
 
     if (stat(device, &sb) < 0) {
@@ -7066,7 +7068,7 @@ qemuDomainSetupDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
 
     for (next = disk->src; next; next = next->backingStore) {
         if (!next->path || !virStorageSourceIsLocalStorage(next) ||
-            !STRPREFIX(next->path, "/dev")) {
+            !STRPREFIX(next->path, DEVPREFIX)) {
             /* Not creating device. Just continue. */
             continue;
         }
@@ -7770,7 +7772,7 @@ qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
 
     for (next = disk->src; next; next = next->backingStore) {
         if (!next->path || !virStorageSourceIsBlockLocal(disk->src) ||
-            !STRPREFIX(next->path, "/dev")) {
+            !STRPREFIX(next->path, DEVPREFIX)) {
             /* Not creating device. Just continue. */
             continue;
         }