diff --git a/fail2ban/server/failregex.py b/fail2ban/server/failregex.py index e8042ddc..a9b144af 100644 --- a/fail2ban/server/failregex.py +++ b/fail2ban/server/failregex.py @@ -157,9 +157,9 @@ class Regex: self._tupleValues.sort() self._altValues = self._altValues if len(self._altValues) else None self._tupleValues = self._tupleValues if len(self._tupleValues) 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 (or tuple) tags: self.getGroups = self._getGroupsWithAlt if (self._altValues or self._tupleValues) else self._getGroups diff --git a/fail2ban/tests/fail2banregextestcase.py b/fail2ban/tests/fail2banregextestcase.py index e300f315..f29f3333 100644 --- a/fail2ban/tests/fail2banregextestcase.py +++ b/fail2ban/tests/fail2banregextestcase.py @@ -140,6 +140,13 @@ class Fail2banRegexTest(LogCaptureTestCase): "test", r".** from $" )) 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"^(?:(?PA)|B)? (?(typo)...) from " + )) + 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( @@ -147,6 +154,7 @@ class Fail2banRegexTest(LogCaptureTestCase): "test", r".*? from $", 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(