pete Posted February 27, 2012 Posted February 27, 2012 The following function, when called, generates: preg_match(): Unknown modifier 't' in /path/to/code.php on line 903 Line 903 is if (preg_match('/^'.$file.': (.*) FOUND$/', $out[0], $regs)) { And I think it's because the slashes aren't correctly escaped? (It's not my code and PHP isn't my poison). function ClamAV ($file) { $out = preg_split('/\n/',`clamscan $file`); if (preg_match('/^'.$file.': (.*) FOUND$/', $out[0], $regs)) { $this->status = 'VIRUS: '.$regs[1]; return true; } else { return false; } }
sonofsanta Posted February 27, 2012 Posted February 27, 2012 I think it's the line before with the error - a couple of the single quotes ' are apostrophes instead ` around clamscan $file - but it doesn't cause a problem until the next line (903) is parsed. Tweak them and try again... EDIT: and FWIW, PHP escaping is done with \, whereas the slashes in that code are / and appear to be wanted as that... I think the code is trying to parse a file path, anyway. So it may be that there's not enough escaping going on. 1
pete Posted February 28, 2012 Author Posted February 28, 2012 A bit of investigation by the PFY reveals there's multiple things wrong with the code. The backticks are apparently correct (because it's calling a system tool (clamav)). The preg_match line doesn't really work properly either. It should (when a file is uploaded) launch clamav, scan the file and then return true (virus found) or false (not found). However, it neglects to check the result properly (clamav will routinely print 13 lines of irrelevant info when the engine is out of date, for example) and even when that's fixed it still doesn't always work because of the funky regex. Not to mention it should be calling clamd ideally (since it's already resident in memory, doesn't print the 13-line "update your engine" whining and is faster to scan files).
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now