Browse Source

tools/qvm-start: use vm.run_with_args to call losetup in the VM

This will fix handling filenames with spaces and shell special
characters.

Reported by @v6ak

Fixes QubesOS/qubes-issues#4860
Marek Marczykowski-Górecki 5 years ago
parent
commit
a2629b1239
2 changed files with 5 additions and 4 deletions
  1. 2 2
      qubesadmin/tests/tools/qvm_start.py
  2. 3 2
      qubesadmin/tools/qvm_start.py

+ 2 - 2
qubesadmin/tests/tools/qvm_start.py

@@ -193,11 +193,11 @@ class TC_00_qvm_start(qubesadmin.tests.QubesTestCase):
                 as mock_run:
             mock_run.return_value = (b'/dev/loop7', b'')
             qubesadmin.tools.qvm_start.main([
-                '--cdrom=other-vm:/home/some/image.iso',
+                '--cdrom=other-vm:/home/some image.iso',
                 'some-vm'],
                 app=self.app)
             mock_run.assert_called_once_with(
-                'losetup -f --show /home/some/image.iso',
+                'losetup -f --show \'/home/some image.iso\'',
                 user='root')
         self.assertAllCalled()
 

+ 3 - 2
qubesadmin/tools/qvm_start.py

@@ -115,8 +115,9 @@ def get_drive_assignment(app, drive_str):
                 loop_name = subprocess.check_output(
                     ['sudo', 'losetup', '-f', '--show', ident])
             else:
-                loop_name, _ = backend_domain.run(
-                    'losetup -f --show ' + ident, user='root')
+                loop_name, _ = backend_domain.run_with_args(
+                    'losetup', '-f', '--show', ident,
+                    user='root')
         except subprocess.CalledProcessError:
             raise qubesadmin.exc.QubesException(
                 'Failed to setup loop device for %s', ident)