Re: [SMARTY-DEV] Serious bug in smarty if safe mode and open basedir set
| From: | Monte Ohrt | Date: | Mon, 16 Sep 2002 15:32:57 +0000 |
| Subject: | Re: [SMARTY-DEV] Serious bug in smarty if safe mode and open basedir set | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-271@lists.php.net to get a copy of this message | ||
Hi Szabo,
I'm not sure if I follow the problem, but if you are using safe_mode you need to set $use_sub_dirs to false, try that. Also I think _create_dir_structure can work with files as well as dirs, so the is_dir at the top of your fix might cause problems.
Monte
Szabo Dénes wrote:
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-- Monte Ohrt <monte@ispi.net> Director of Technology, ispi Inc.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