Skip to content

Commit

Permalink
Assert number of arguments to LVM ops are right
Browse files Browse the repository at this point in the history
If the number of arguments is wrong, any extra arguments would be
ignored, and any missing arguments would result in a confusing error.
  • Loading branch information
DemiMarie committed Feb 5, 2022
1 parent 3d6b8f0 commit ea4c9e8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qubes/storage/lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,21 +751,27 @@ def _get_lvm_cmdline(cmd):
'''
action = cmd[0]
if action == 'remove':
assert len(cmd) == 2, 'wrong number of arguments for remove'
assert not cmd[1].startswith('/'), 'absolute path to ‘remove’???'
lvm_cmd = ['lvremove', '--force', '--', cmd[1]]
elif action == 'clone':
assert len(cmd) == 3, 'wrong number of arguments for clone'
lvm_cmd = ['lvcreate', '--setactivationskip=n', '--activate=y',
'--snapshot', '--type=thin', '--name=' + cmd[2],
'--', cmd[1]]
elif action == 'create':
assert len(cmd) == 4, 'wrong number of arguments for create'
lvm_cmd = ['lvcreate', '--thin', '--setactivationskip=n',
'--activate=y', '--name=' + cmd[2],
'--virtualsize=' + str(cmd[3]) + 'B', '--', cmd[1]]
elif action == 'extend':
assert len(cmd) == 3, 'wrong number of arguments for extend'
lvm_cmd = ["lvextend", "--size=" + cmd[2] + 'B', '--', cmd[1]]
elif action == 'activate':
assert len(cmd) == 2, 'wrong number of arguments for activate'
lvm_cmd = ['lvchange', '--activate=y', '--', cmd[1]]
elif action == 'rename':
assert len(cmd) == 3, 'wrong number of arguments for rename'
lvm_cmd = ['lvrename', '--', cmd[1], cmd[2]]
else:
raise NotImplementedError('unsupported action: ' + action)
Expand Down

0 comments on commit ea4c9e8

Please sign in to comment.