2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-22 18:17:09 +00:00

Merge Small fixes in MountRule

- Removed unnecessary variable source_is_path in mount rules
- Changed a string to a r-string to avoid an 'invalid escape sequence \s' warning

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1172
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
This commit is contained in:
Georgia Garcia 2024-03-04 11:53:51 +00:00
commit 3ea2bfec56

View File

@ -51,13 +51,13 @@ join_valid_fs = '|'.join(valid_fs)
sep = r"\s*[\s,]\s*"
fs_type_pattern = r"\b(?P<fstype_or_vfstype>fstype|vfstype)\b\s*(?P<fstype_equals_or_in>=|in)\s*"\
r"(?P<fstype>\(\s*(" + join_valid_fs + ")(" + sep + "(" + join_valid_fs + "))*\s*\)|"\
r"(?P<fstype>\(\s*(" + join_valid_fs + ")(" + sep + "(" + join_valid_fs + r"))*\s*\)|"\
r"\{\s*(" + join_valid_fs + ")(" + sep + "(" + join_valid_fs + r"))*\s*\}|(\s*" + join_valid_fs + "))"\
option_pattern = r"\s*(\boption(s?)\b\s*(?P<options_equals_or_in>=|in)\s*"\
r"(?P<options>\(\s*(" + join_valid_flags + ")(" + sep + "(" + join_valid_flags + r"))*\s*\)|" \
"(\s*" + join_valid_flags + ")"\
r"(\s*" + join_valid_flags + ")"\
"))?"
mount_condition_pattern = rf"({fs_type_pattern})?\s*({option_pattern})?"
@ -103,13 +103,7 @@ class MountRule(BaseRule):
raise AppArmorException(_('Passed unknown options keyword to %s: %s') % (type(self).__name__, ' '.join(unknown_items)))
self.is_options_equal = options[0] if not self.all_options else None
if source != self.ALL and source[0].isalpha():
self.source = source
self.all_source = False
self.source_is_path = False
else:
self.source_is_path = True
self.source, self.all_source = self._aare_or_all(source, 'source', is_path=self.source_is_path, log_event=log_event)
self.source, self.all_source = self._aare_or_all(source, 'source', is_path=False, log_event=log_event)
if not self.all_fstype and self.is_fstype_equal not in ("=", "in"):
raise AppArmorBug(f'Invalid is_fstype_equal : {self.is_fstype_equal}')
@ -223,12 +217,7 @@ class MountRule(BaseRule):
return False
if not self._is_covered_list(self.options, self.all_options, other_rule.options, other_rule.all_options, 'options'):
return False
if not self.source_is_path and not other_rule.source_is_path:
if self.source != other_rule.source:
return False
elif self.source_is_path != other_rule.source_is_path:
return False
elif not self._is_covered_aare(self.source, self.all_source, other_rule.source, other_rule.all_source, 'source'):
if not self._is_covered_aare(self.source, self.all_source, other_rule.source, other_rule.all_source, 'source'):
return False
if not self._is_covered_aare(self.dest, self.all_dest, other_rule.dest, other_rule.all_dest, 'dest'):
return False
@ -244,12 +233,7 @@ class MountRule(BaseRule):
return False
if self.fstype != rule_obj.fstype or self.options != rule_obj.options:
return False
if not self.source_is_path and not rule_obj.source_is_path:
if self.source != rule_obj.source:
return False
elif self.source_is_path != rule_obj.source_is_path:
return False
elif not self._is_equal_aare(self.source, self.all_source, rule_obj.source, rule_obj.all_source, 'source'):
if not self._is_equal_aare(self.source, self.all_source, rule_obj.source, rule_obj.all_source, 'source'):
return False
if not self._is_equal_aare(self.dest, self.all_dest, rule_obj.dest, rule_obj.all_dest, 'dest'):
return False