From a2629b12392c8280d414860c922ed86390240776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 28 Feb 2019 05:51:49 +0100 Subject: [PATCH] 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 --- qubesadmin/tests/tools/qvm_start.py | 4 ++-- qubesadmin/tools/qvm_start.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/qubesadmin/tests/tools/qvm_start.py b/qubesadmin/tests/tools/qvm_start.py index 9ac5d98..519a3e9 100644 --- a/qubesadmin/tests/tools/qvm_start.py +++ b/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() diff --git a/qubesadmin/tools/qvm_start.py b/qubesadmin/tools/qvm_start.py index a522f89..4670f44 100644 --- a/qubesadmin/tools/qvm_start.py +++ b/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)