bug? security hole? undocumented magic in php?
| From: | Greg Stark | Date: | Fri, 25 Apr 2003 19:49:46 +0000 |
| Subject: | bug? security hole? undocumented magic in php? | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-9379@lists.php.net to get a copy of this message | ||
So in trying to implement my pre-filter I was stumped on how to use
prereg_replace properly and safely in PHP. So I skimmed the Smarty source to
see how it was done there.
I was surprised to find code in the Smarty source that was exactly what I had
dismissed as incorrect. In fact I assumed this would be a security hole. So
I'm curious to know if there's something I'm missing. Perhaps PHP has some
magic to deal with this case that my books and manuals don't mention?
In the code:
$template_source = preg_replace("!({$ldq})\*(.*?)\*({$rdq})!se",
"'\\1*'.str_repeat(\"\n\",
substr_count('\\2', \"\n\")) .'*\\3'",
$template_source);
a) Shouldn't \\1,\\2,\\3 actually be \$1,\$2,\$3 ?
b) what happens if there's a single quote in the second subexpression?
wouldn't that result in evaluating an expression like substr_count('foo'bar')
or worse, like substr_count('foo'+delete_all_my_files()+'bar) ?
Unless PHP is doing some magic here it seems like a gaping security hole.
I was expecting to find something vaguely equivalent to the perl
while (/foo(.*?)/g) {
$1 = "bar".
}
Which, while a bit gross, is actually secure. But as near as I can tell PHP
doesn't support anything like that?
--
greg