Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some safeguards for invalid firewall rules #139

Merged
merged 1 commit into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions qubesadmin/tests/tools/qvm_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ def test_006_dsthost_aliases(self):
qubesadmin.firewall.Rule(
None, action='accept', dsthost='127.0.0.1/32'))

def test_007_none_errors(self):
ns = argparse.Namespace()
with self.assertRaises(argparse.ArgumentError):
self.action(None, ns, ['dsthost=', 'action=accept'])
with self.assertRaises(argparse.ArgumentError):
self.action(None, ns, ['dsthost=127.0.0.1', 'dstports=',
'action=accept'])
with self.assertRaises(argparse.ArgumentError):
self.action(None, ns, ['dsthost=127.0.0.1', 'icmptype=',
'action=accept'])


class TC_10_qvm_firewall(qubesadmin.tests.QubesTestCase):
def setUp(self):
Expand Down
3 changes: 3 additions & 0 deletions qubesadmin/tools/qvm_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def __call__(self, _parser, namespace, values, option_string=None):
allowed_opts = assumed_order + ['specialtarget', 'comment', 'expire']
kwargs = {}
for opt in values:
if opt[-1] == '=':
raise argparse.ArgumentError(
None, 'invalid rule description: {}'.format(opt))
opt_elements = opt.split('=')
if len(opt_elements) == 2:
key, value = opt_elements
Expand Down