Serious bug in smarty if safe mode and open basedir set
| From: | Szabo Dénes | Date: | Sun, 15 Sep 2002 22:26:46 +0000 |
| Subject: | Serious bug in smarty if safe mode and open basedir set | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-270@lists.php.net to get a copy of this message | ||
Hi!
(This is my frirst letter, sorry my english... :) )
I find a bug isn Smarty.class.php:
I work with php in safe mode, and i set the open basedir in apache config
in my virtual host config
php_admin_value open_basedir .:/home/donci/public_html/pentzadmin/:
/home/donci/public_html/pentz/: /home/donci/public_html/PHP/:
/home/donci/tmp/smarty/
(I put spaces this line to correct wordwrap).
My smarty compile dir is set by
define( 'SMARTY_COMPILEDIR', '/home/donci/tmp/smarty/' );
$smarty->compile_dir = SMARTY_COMPILEDIR . 'templates_c';
This dir is in open basedir path.
There is the bug: if there are new template, smarty probes make new dirs in
/home/donci/tmp/smarty/ (for example: %%-143/%%883838)
The _create_dir_structure($dir) function is wrond, because it probes make
dir, like:
is_dir /home -> ok then is_dir /home/donci ..
is dir /home/donci/tmp/smarty/%-143 ->no mkdir /home/donci/tmp/smarty/%-143
But in safe mode the is_dir /home is not allowed...
(is_dir /home/donci/tmp/smarty/ allowed.)
my patch that corrects this error is:
function _create_dir_structure($dir)
{
if ( !@is_dir( $dir ) ) {
$dir_parts = preg_split('!\\'.DIR_SEP.'+!', $dir, -1,
PREG_SPLIT_NO_EMPTY);
$dirdepth = sizeof( $dir_parts);
$depth = $dirdepth;
while( $depth > 1 and $depth <= $dirdepth ) {
$dirparts = array_slice( $dir_parts, 0, $depth );
$new_dir = DIR_SEP . implode( DIR_SEP , $dirparts );
if ( @mkdir($new_dir) ) {
$depth++;
}
else {
$depth--;
}
}
if ( $depth < $dirdepth ) {
$this->trigger_error('problem creating directory
"' . $dir . '"');
return false;
}
}
}
This patch make directories in reverse order, and makes fewer dir
examination.
bye!
Den