From 933fe652e6a7d7857bd9d700a3d21709a6b0000b Mon Sep 17 00:00:00 2001 From: mohrt Date: Mon, 6 May 2002 14:50:37 +0000 Subject: [PATCH] update fetch function with more error checking --- libs/plugins/function.fetch.php | 34 ++++++++++++++++----------------- plugins/function.fetch.php | 34 ++++++++++++++++----------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/libs/plugins/function.fetch.php b/libs/plugins/function.fetch.php index 467f228e..46433d7f 100644 --- a/libs/plugins/function.fetch.php +++ b/libs/plugins/function.fetch.php @@ -28,17 +28,17 @@ function smarty_function_fetch($params, &$smarty) if (!$resource_is_secure) { $smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed"); return; - } - if (!@is_readable($file)) { - $smarty->_trigger_plugin_error("fetch cannot read file '$file'"); - return; } // fetch the file - $fp = fopen($file,'r'); - while(!feof($fp)) { - $content .= fgets ($fp,4096); + if($fp = @fopen($file,'r')) { + while(!feof($fp)) { + $content .= fgets ($fp,4096); + } + fclose($fp); + } else { + $smarty->_trigger_plugin_error("fetch cannot read file '$file'"); + return; } - fclose($fp); } else { // not a local file if(preg_match('!^http://!i',$file)) { @@ -127,12 +127,6 @@ function smarty_function_fetch($params, &$smarty) return; } break; - case "cluster_host": - if(!empty($param_value) - && (gethostbyname($param_value) != $param_value)) { - $server_name = $param_value; - } - break; default: $smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'"); return; @@ -194,11 +188,15 @@ function smarty_function_fetch($params, &$smarty) } } else { // ftp fetch - $fp = fopen($file,'r'); - while(!feof($fp)) { - $content .= fgets ($fp,4096); + if($fp = @fopen($file,'r')) { + while(!feof($fp)) { + $content .= fgets ($fp,4096); + } + fclose($fp); + } else { + $smarty->_trigger_plugin_error("fetch cannot read file '$file'"); + return; } - fclose($fp); } } diff --git a/plugins/function.fetch.php b/plugins/function.fetch.php index 467f228e..46433d7f 100644 --- a/plugins/function.fetch.php +++ b/plugins/function.fetch.php @@ -28,17 +28,17 @@ function smarty_function_fetch($params, &$smarty) if (!$resource_is_secure) { $smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed"); return; - } - if (!@is_readable($file)) { - $smarty->_trigger_plugin_error("fetch cannot read file '$file'"); - return; } // fetch the file - $fp = fopen($file,'r'); - while(!feof($fp)) { - $content .= fgets ($fp,4096); + if($fp = @fopen($file,'r')) { + while(!feof($fp)) { + $content .= fgets ($fp,4096); + } + fclose($fp); + } else { + $smarty->_trigger_plugin_error("fetch cannot read file '$file'"); + return; } - fclose($fp); } else { // not a local file if(preg_match('!^http://!i',$file)) { @@ -127,12 +127,6 @@ function smarty_function_fetch($params, &$smarty) return; } break; - case "cluster_host": - if(!empty($param_value) - && (gethostbyname($param_value) != $param_value)) { - $server_name = $param_value; - } - break; default: $smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'"); return; @@ -194,11 +188,15 @@ function smarty_function_fetch($params, &$smarty) } } else { // ftp fetch - $fp = fopen($file,'r'); - while(!feof($fp)) { - $content .= fgets ($fp,4096); + if($fp = @fopen($file,'r')) { + while(!feof($fp)) { + $content .= fgets ($fp,4096); + } + fclose($fp); + } else { + $smarty->_trigger_plugin_error("fetch cannot read file '$file'"); + return; } - fclose($fp); } }