Skip to content

Commit c65b6fd

Browse files
committed
Merge remote-tracking branch 'origin/pr/559'
* origin/pr/559: Fix the issue URL in the log message Remove accidentally duplicated test function firewall: avoid crash on qubesdb long path errors
2 parents 5c286db + 7518028 commit c65b6fd

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

qubesagent/firewall.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,18 @@ def update_dns_info(self, source, dns):
167167
self.qdb.rm('/dns/{}/'.format(source))
168168

169169
for host, hostaddrs in dns.items():
170-
self.qdb.write('/dns/{}/{}'.format(source, host), str(hostaddrs))
170+
path = '/dns/{}/{}'.format(source, host)
171+
try:
172+
self.qdb.write(path, str(hostaddrs))
173+
except Exception as err:
174+
if len(path) > 64 and err.args == (0, 'Error'):
175+
self.log.error(('Unable to add DNS information for {} ({})'
176+
' due to qubesdb path length limit').format(
177+
host, source))
178+
self.log.error('See https://github.com/QubesOS/'
179+
'qubes-issues/issues/9084')
180+
else:
181+
raise
171182

172183
def update_handled(self, addr):
173184
"""

qubesagent/test_firewall.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def rm(self, path):
4040
self.entries.pop(path)
4141

4242
def write(self, path, val):
43+
if len(path) > 64:
44+
raise DummyQubesDBError(0, 'Error')
4345
self.entries[path] = val
4446

4547
def multiread(self, prefix):
@@ -65,6 +67,8 @@ def read_watch(self):
6567
except IndexError:
6668
return None
6769

70+
class DummyQubesDBError(Exception):
71+
"Raised by QubesDB"
6872

6973
class FirewallWorker(qubesagent.firewall.FirewallWorker):
7074
def __init__(self):
@@ -159,6 +163,23 @@ def test_701_dns_info(self):
159163
self.obj.apply_rules('10.137.0.1', [{'action': 'drop'}])
160164
self.assertIsNone(self.obj.qdb.read('/dns/10.137.0.1/ripe.net'))
161165

166+
def test_702_dns_info_qubesdb_path_length_crash(self):
167+
self.obj.conntrack_get_connections = Mock(return_value=[])
168+
rules = [
169+
{'action': 'accept', 'proto': 'tcp',
170+
'dstports': '443-443', 'dsthost': 'www.google.com'},
171+
{'action': 'accept', 'proto': 'tcp',
172+
'dstports': '443-443', 'dsthost': 'prod-dynamite-prod-05-us-signaler-pa.clients6.google.com'},
173+
{'action': 'drop'},
174+
]
175+
self.obj.apply_rules('10.137.0.22', rules)
176+
self.assertIsNotNone(self.obj.qdb.read('/dns/10.137.0.22/www.google.com'))
177+
# Unfortunately, this is assertIsNone until the QubesDB path length limit is raised.
178+
self.assertIsNone(self.obj.qdb.read('/dns/10.137.0.22/prod-dynamite-prod-05-us-signaler-pa.clients6.google.com'))
179+
self.obj.apply_rules('10.137.0.22', [{'action': 'drop'}])
180+
self.assertIsNone(self.obj.qdb.read('/dns/10.137.0.22/www.google.com'))
181+
self.assertIsNone(self.obj.qdb.read('/dns/10.137.0.22/prod-dynamite-prod-05-us-signaler-pa.clients6.google.com'))
182+
162183
class TestNftablesWorker(TestCase, WorkerCommon):
163184
def setUp(self):
164185
super(TestNftablesWorker, self).setUp()

0 commit comments

Comments
 (0)