Whitespace and Comment handling for pattern files

The pattern files are large and complex enough to justify some whitespace and comments to explain what each entry is.

Added logic to check if the line is empty or if the first character is equal to '#' before using it as a pattern.  Simply skips over empty and commented lines.
This commit is contained in:
nichogenius
2017-07-25 23:55:37 -06:00
committed by GitHub
parent a371961928
commit 8122d11eff

View File

@@ -167,6 +167,12 @@ class MalwareScanner
array_push($patterns, "googleBot", "htaccess");
}
foreach ($patterns as $toSearch) {
if (!$toSearch) {
continue;
}
if ($toSearch[0] === '#') {
continue;
}
$substrCount = substr_count($fileContent, $toSearch);
if ($substrCount > 0) {
$found = true;
@@ -176,6 +182,12 @@ class MalwareScanner
if (!$found) {
$patterns = $this->loadPatterns(dirname(__FILE__) . '/patterns_re.txt');
if (!$toSearch) {
continue;
}
if ($toSearch[0] === '#') {
continue;
}
foreach ($patterns as $toSearch) {
if (preg_match('/' . $toSearch . '/is', $fileContent)) {
$found = true;