+ Post New Thread
Results 1 to 3 of 3
Web Development Thread, PHP - I think this is broken, but checking I'm right. in Coding and Web Development; The following function, when called, generates: preg_match(): Unknown modifier 't' in /path/to/code.php on line 903 Line 903 is Code: if ...
  1. #1


    Join Date
    Dec 2005
    Location
    In the server room, with the lead pipe.
    Posts
    4,619
    Thank Post
    275
    Thanked 777 Times in 604 Posts
    Rep Power
    223

    PHP - I think this is broken, but checking I'm right.

    The following function, when called, generates: preg_match(): Unknown modifier 't' in /path/to/code.php on line 903

    Line 903 is
    Code:
     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).

    Code:
    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;
        }
    }

  2. #2

    sonofsanta's Avatar
    Join Date
    Dec 2009
    Location
    Lincolnshire, UK
    Posts
    4,829
    Thank Post
    840
    Thanked 1,399 Times in 962 Posts
    Blog Entries
    47
    Rep Power
    603
    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.

  3. Thanks to sonofsanta from:

    pete (28th February 2012)

  4. #3


    Join Date
    Dec 2005
    Location
    In the server room, with the lead pipe.
    Posts
    4,619
    Thank Post
    275
    Thanked 777 Times in 604 Posts
    Rep Power
    223
    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).

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 3
    Last Post: 2nd July 2011, 02:06 PM
  2. [Video] I don't think this is fake.
    By laserblazer in forum Jokes/Interweb Things
    Replies: 10
    Last Post: 15th February 2011, 09:45 PM
  3. [Pics] I think this is a new record
    By somabc in forum Jokes/Interweb Things
    Replies: 8
    Last Post: 21st October 2010, 09:15 PM
  4. Replies: 0
    Last Post: 1st July 2007, 08:04 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •