]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_shim: Require absolute path for root directory
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 22 Mar 2023 11:39:21 +0000 (12:39 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 22 Mar 2023 14:53:33 +0000 (15:53 +0100)
The virConnectOpen(), well virConnectOpenInternal() reports an
error if embed root is not an absolute path. This is a fair
requirement, but our qemu_shim doesn't check this requirement and
passes the path to mkdir(), only to fail later on, leaving the
empty directory behind:

  $ ls -d asd
  ls: cannot access 'asd': No such file or directory

  $ virt-qemu-run -r asd whatever.xml
  virt-qemu-run: cannot open qemu:///embed?root=asd: unsupported configuration: root path must be absolute

  $ ls -d asd
  asd

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
src/qemu/qemu_shim.c

index b642f6175a84e7dfb1dfc3101795a62fde4324cc..7fdd69b5389a4d7ef12da9e69e23fa5e1ebfab6e 100644 (file)
@@ -214,10 +214,18 @@ int main(int argc, char **argv)
         }
         tmproot = true;
 
-    } else if (g_mkdir_with_parents(root, 0755) < 0) {
-        g_printerr("%s: cannot create dir: %s\n",
-                   argv[0], g_strerror(errno));
-        goto cleanup;
+    } else {
+        if (!g_path_is_absolute(root)) {
+            g_printerr("%s: the root directory must be an absolute path\n",
+                       argv[0]);
+            goto cleanup;
+        }
+
+        if (g_mkdir_with_parents(root, 0755) < 0) {
+            g_printerr("%s: cannot create dir: %s\n",
+                       argv[0], g_strerror(errno));
+            goto cleanup;
+        }
     }
 
     if (chmod(root, 0755) < 0) {