diff options
author | sebres <serg.brester@sebres.de> | 2022-09-08 15:49:57 +0200 |
---|---|---|
committer | sebres <serg.brester@sebres.de> | 2022-09-08 16:04:46 +0200 |
commit | 5e74499ffd2358d39cf6d4017fc66ce2e093eb6d (patch) | |
tree | 003ada2132ee38176fc7d5c3d3e0117dca98ec8b /fail2ban | |
parent | 35eb9acaee6660e2a77b3ce85f0a56a57ed94cea (diff) | |
download | fail2ban-5e74499ffd2358d39cf6d4017fc66ce2e093eb6d.tar.gz |
provides details of failed regex compilation in the error message we throw in Regex-constructor (it's good to know what exactly is wrong)
Diffstat (limited to 'fail2ban')
-rw-r--r-- | fail2ban/server/failregex.py | 6 | ||||
-rw-r--r-- | fail2ban/tests/fail2banregextestcase.py | 8 |
2 files changed, 11 insertions, 3 deletions
diff --git a/fail2ban/server/failregex.py b/fail2ban/server/failregex.py index 15a7699f..5cf18f80 100644 --- a/fail2ban/server/failregex.py +++ b/fail2ban/server/failregex.py @@ -145,9 +145,9 @@ class Regex: n = ALTNAME_CRE.match(k).group(1) self._altValues[k] = n self._altValues = list(self._altValues.items()) if len(self._altValues) else None - except sre_constants.error: - raise RegexException("Unable to compile regular expression '%s'" % - regex) + except sre_constants.error as e: + raise RegexException("Unable to compile regular expression '%s':\n%s" % + (regex, e)) # set fetch handler depending on presence of alternate tags: self.getGroups = self._getGroupsWithAlt if self._altValues else self._getGroups diff --git a/fail2ban/tests/fail2banregextestcase.py b/fail2ban/tests/fail2banregextestcase.py index 00808ddd..e6ef2707 100644 --- a/fail2ban/tests/fail2banregextestcase.py +++ b/fail2ban/tests/fail2banregextestcase.py @@ -133,6 +133,13 @@ class Fail2banRegexTest(LogCaptureTestCase): "test", r".** from <HOST>$" )) self.assertLogged("Unable to compile regular expression") + self.assertLogged("multiple repeat", "at position 2", all=False); # details of failed compilation + self.pruneLog() + self.assertFalse(_test_exec( + "test", r"^(?:(?P<type>A)|B)? (?(typo)...) from <ADDR>" + )) + self.assertLogged("Unable to compile regular expression") + self.assertLogged("unknown group name: 'typo'", "at position 23", all=False); # details of failed compilation def testWrongIngnoreRE(self): self.assertFalse(_test_exec( @@ -140,6 +147,7 @@ class Fail2banRegexTest(LogCaptureTestCase): "test", r".*? from <HOST>$", r".**" )) self.assertLogged("Unable to compile regular expression") + self.assertLogged("multiple repeat", "at position 2", all=False); # details of failed compilation def testWrongFilterOptions(self): self.assertFalse(_test_exec( |