It would be nice to identify these as potential issues: http://drupal.org/node/750148
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | drupalcs-sniff-for-preg-functions-1730274-4.patch | 4.1 KB | das-peter |
| #2 | drupalcs-sniff-for-preg-functions-1730274-2.patch | 4.01 KB | das-peter |
Comments
Comment #1
das-peter commentedNice idea, I give it a try.
Comment #2
das-peter commentedHere we go :)
The sniff scans the pattern of all relevant
preg_*functions.Currently the sniff is limited to plain text patterns - if the pattern is provided by a variable, the sniff is skipped.
I think we can extend the sniff to provide a limited support for patterns in variables / constants but it won't be bulletproof.
I didn't push the change right away since I'd like to have some feedback first.
Comment #3
klausiyou should use %s placeholders in error messages, so that they can be easily overridden.
Will this ever raise any false positives? I always tried to keep drupalcs as clean as possible and to avoid wrongly detected "mistakes", because people tend to believe in the error reports and "correct" them without thinking. Coder module has quite a few security checks that often produce silly false positives.
But otherwise looks good to me. Glad you found my generic function call sniff class :-)
Comment #4
das-peter commentedPatch adjusted.
Well I guess if someone really knows what he's doing the "e" flag is save = false positive.
But I don't see a need to use the "e" flag at all since the documentation says:
It is generally possible to instead use preg_replace_callback() to transform the matches and generate a replacement string while avoiding the risk that user input may be executed as PHP.Comment #5
das-peter commentedTalked with klausi @drupalcon about the sniff -> agreed on committing it. Done in: http://drupalcode.org/project/drupalcs.git/commit/3fff0bb8780070c05e88a9...
Comment #7
Désiré commentedCode sniffer warns even if no 'e' flag, for example on this (because of the 'e' charf after the escaped '/'):
Comment #8
Désiré commentedSorry, I've found, that this is a duplicate: #1779020: Invalid match for "Using the e flag in preg_match"