aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2022-08-31 10:06:30 -0400
committerJake Hunsaker <jhunsake@redhat.com>2022-09-06 10:02:37 -0400
commit151f8e8aeab06e19ec6888279225b91f3898c327 (patch)
tree43ddb0eb4a7161b245bfea0e379d7298199f42a9
parentf68b4047f3b1e934c4fa2e728539923b52b654be (diff)
downloadsos-151f8e8aeab06e19ec6888279225b91f3898c327.tar.gz
[cleaner] Check --domains values for validity
The domain parser is built to understand actual names, e.g. 'example.com', and not operate off of just 'example' despite the fact that the parser handles TLDs separately. To safeguard against potential errors when trying to parse the latter example above as an actual domain, validate any values passed to `--domains` during cleaner initialization. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r--sos/cleaner/__init__.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/sos/cleaner/__init__.py b/sos/cleaner/__init__.py
index a2c4c340..7940999d 100644
--- a/sos/cleaner/__init__.py
+++ b/sos/cleaner/__init__.py
@@ -111,6 +111,8 @@ class SoSCleaner(SoSComponent):
# when obfuscating a SoSCollector run during archive extraction
os.makedirs(os.path.join(self.tmpdir, 'cleaner'), exist_ok=True)
+ self.validate_parser_values()
+
self.cleaner_mapping = self.load_map_file()
os.umask(0o77)
self.in_place = in_place
@@ -316,6 +318,18 @@ third party.
if self.nested_archive:
self.nested_archive.ui_name = self.nested_archive.description
+ def validate_parser_values(self):
+ """Check any values passed to the parsers via the commandline, e.g.
+ the --domains option, to ensure that they are valid for the parser in
+ question.
+ """
+ for _dom in self.opts.domains:
+ if len(_dom.split('.')) < 2:
+ raise Exception(
+ f"Invalid value '{_dom}' given: --domains values must be "
+ "actual domains"
+ )
+
def execute(self):
"""SoSCleaner will begin by inspecting the TARGET option to determine
if it is a directory, archive, or archive of archives.