utils: fix encoding '+' for qubes.VMExec

'+' in an argument needs to be encoded too, otherwise it is interpreted
as arguments separator.
This commit is contained in:
Marek Marczykowski-Górecki 2020-08-04 21:59:13 +02:00
parent b7eca976b5
commit f16f14b020
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 3 additions and 3 deletions

View File

@ -116,8 +116,8 @@ class TestVMUsage(qubesadmin.tests.QubesTestCase):
class TestVMExecEncode(qubesadmin.tests.QubesTestCase): class TestVMExecEncode(qubesadmin.tests.QubesTestCase):
def test_00_encode(self): def test_00_encode(self):
self.assertEqual( self.assertEqual(
qubesadmin.utils.encode_for_vmexec(['ls', '-a']), qubesadmin.utils.encode_for_vmexec(['ls', '-a', '+x']),
'ls+--a') 'ls+--a+-2Bx')
self.assertEqual( self.assertEqual(
qubesadmin.utils.encode_for_vmexec( qubesadmin.utils.encode_for_vmexec(
['touch', '/home/user/.profile']), ['touch', '/home/user/.profile']),

View File

@ -161,6 +161,6 @@ def encode_for_vmexec(args):
parts = [] parts = []
for arg in args: for arg in args:
part = re.sub(br'[^a-zA-Z0-9_.+]', encode, arg.encode('utf-8')) part = re.sub(br'[^a-zA-Z0-9_.]', encode, arg.encode('utf-8'))
parts.append(part) parts.append(part)
return b'+'.join(parts).decode('ascii') return b'+'.join(parts).decode('ascii')