Re: [SMARTY] bug? security hole? undocumented magic in php?

From: Date: Fri, 25 Apr 2003 20:16:52 +0000
Subject: Re: [SMARTY] bug? security hole? undocumented magic in php?
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9380@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. There must be some magic happening. Otherwise something like the following would produce an error: $str = "This %%is ' a%% test"; $newstr = preg_replace('/%%(.*)%%/e',"strtoupper('\\1')",$str); PHP must apply addslashes() to either the matches or the entire string at some point. ---John Holmes...

« previous php.smarty.general (#9380) next »