From 8122d11eff1049532e8ea15416202c5e787b14aa Mon Sep 17 00:00:00 2001 From: nichogenius Date: Tue, 25 Jul 2017 23:55:37 -0600 Subject: [PATCH] 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. --- scan.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scan.php b/scan.php index a0cad20..25762dc 100644 --- a/scan.php +++ b/scan.php @@ -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;