From 0ee335237a0add705a440e3b86bf0165ebde0495 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Fri, 18 Jan 2019 11:27:24 +0000 Subject: [PATCH] Improve the protection of empty regular expressions (improves issue #61). --- volatility/framework/layers/scanners/multiregexp.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/volatility/framework/layers/scanners/multiregexp.py b/volatility/framework/layers/scanners/multiregexp.py index 6e38ecbdc..31ecfab87 100644 --- a/volatility/framework/layers/scanners/multiregexp.py +++ b/volatility/framework/layers/scanners/multiregexp.py @@ -33,13 +33,15 @@ class MultiRegexp(object): self._pattern_strings.append(pattern) def preprocess(self) -> None: + if not self._pattern_strings: + raise ValueError("No strings to compile into a regular expression") self._regex = re.compile(b'|'.join(map(re.escape, self._pattern_strings))) def search(self, haystack: bytes) \ -> Generator[Tuple[int, Union[str, bytes]], None, None]: if not isinstance(haystack, bytes): raise TypeError("Search haystack must be a byte string") - if not self._regex: + if not self._regex.pattern: raise ValueError("MultiRegexp cannot be used with an empty set of search strings") for match in re.finditer(self._regex, haystack): yield (match.start(0), match.group())