From 151f8e8aeab06e19ec6888279225b91f3898c327 Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Wed, 31 Aug 2022 10:06:30 -0400 Subject: [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 --- sos/cleaner/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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. -- cgit