[PATCH 3/3] qemuDomainCreateDevice: Be more careful about device path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 40bed1b396..3ecc30c7b5 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -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) {
@@ -7064,7 +7066,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;
         }
@@ -7768,7 +7770,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;
         }
-- 
2.11.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux