From 7af9f9aa1db2a8c8c5de3527f578999ce05881fe Mon Sep 17 00:00:00 2001 From: Matthias Ruester Date: Wed, 26 Apr 2017 13:57:30 +0200 Subject: [PATCH] Check if ini_get/ini_set is not disabled before using it --- libs/sysplugins/smarty_internal_cacheresource_file.php | 3 ++- .../smarty_internal_config_file_compiler.php | 4 +++- .../smarty_internal_method_clearcompiledtemplate.php | 3 ++- libs/sysplugins/smarty_internal_resource_php.php | 10 +++++++--- .../smarty_internal_runtime_cacheresourcefile.php | 3 ++- .../smarty_internal_smartytemplatecompiler.php | 4 +++- libs/sysplugins/smarty_template_compiled.php | 3 ++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/libs/sysplugins/smarty_internal_cacheresource_file.php b/libs/sysplugins/smarty_internal_cacheresource_file.php index 7df4ddffb..5e745689d 100644 --- a/libs/sysplugins/smarty_internal_cacheresource_file.php +++ b/libs/sysplugins/smarty_internal_cacheresource_file.php @@ -108,7 +108,8 @@ public function writeCachedContent(Smarty_Internal_Template $_template, $content if ($_template->smarty->ext->_writeFile->writeFile($_template->cached->filepath, $content, $_template->smarty) === true ) { - if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { + if (function_exists('opcache_invalidate') + && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)) { opcache_invalidate($_template->cached->filepath, true); } elseif (function_exists('apc_compile_file')) { apc_compile_file($_template->cached->filepath); diff --git a/libs/sysplugins/smarty_internal_config_file_compiler.php b/libs/sysplugins/smarty_internal_config_file_compiler.php index b1ef958cd..a3324fcfd 100644 --- a/libs/sysplugins/smarty_internal_config_file_compiler.php +++ b/libs/sysplugins/smarty_internal_config_file_compiler.php @@ -117,7 +117,9 @@ public function compileTemplate(Smarty_Internal_Template $template) /* @var Smarty_Internal_ConfigFileParser $this->parser */ $this->parser = new $this->parser_class($this->lex, $this); - if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { + if (function_exists('mb_internal_encoding') + && function_exists('ini_get') + && ((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } else { diff --git a/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php b/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php index a1f1a80bb..cd1adada3 100644 --- a/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php +++ b/libs/sysplugins/smarty_internal_method_clearcompiledtemplate.php @@ -111,7 +111,8 @@ public function clearCompiledTemplate(Smarty $smarty, $resource_name = null, $co if ($unlink && @unlink($_filepath)) { $_count ++; - if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { + if (function_exists('opcache_invalidate') + && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)) { opcache_invalidate($_filepath, true); } } diff --git a/libs/sysplugins/smarty_internal_resource_php.php b/libs/sysplugins/smarty_internal_resource_php.php index 52e7096b3..1b261036e 100644 --- a/libs/sysplugins/smarty_internal_resource_php.php +++ b/libs/sysplugins/smarty_internal_resource_php.php @@ -37,7 +37,7 @@ class Smarty_Internal_Resource_Php extends Smarty_Internal_Resource_File */ public function __construct() { - $this->short_open_tag = ini_get('short_open_tag'); + $this->short_open_tag = function_exists('ini_get') ? ini_get('short_open_tag') : 1; } /** @@ -79,13 +79,17 @@ public function renderUncompiled(Smarty_Template_Source $source, Smarty_Internal extract($_template->getTemplateVars()); // include PHP template with short open tags enabled - ini_set('short_open_tag', '1'); + if (function_exists('ini_set')) { + ini_set('short_open_tag', '1'); + } /** @var Smarty_Internal_Template $_smarty_template * used in included file */ $_smarty_template = $_template; include($source->filepath); - ini_set('short_open_tag', $this->short_open_tag); + if (function_exists('ini_set')) { + ini_set('short_open_tag', $this->short_open_tag); + } } /** diff --git a/libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php b/libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php index 7b7a9f685..24cc749da 100644 --- a/libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php +++ b/libs/sysplugins/smarty_internal_runtime_cacheresourcefile.php @@ -125,7 +125,8 @@ public function clear(Smarty $smarty, $resource_name, $cache_id, $compile_id, $e } } $_count += @unlink($_filepath) ? 1 : 0; - if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { + if (function_exists('opcache_invalidate') + && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)) { opcache_invalidate($_filepath, true); } } diff --git a/libs/sysplugins/smarty_internal_smartytemplatecompiler.php b/libs/sysplugins/smarty_internal_smartytemplatecompiler.php index 8cd37dd56..c227a4482 100644 --- a/libs/sysplugins/smarty_internal_smartytemplatecompiler.php +++ b/libs/sysplugins/smarty_internal_smartytemplatecompiler.php @@ -94,7 +94,9 @@ protected function doCompile($_content, $isTemplateSource = false) if ($isTemplateSource && $this->template->caching) { $this->parser->insertPhpCode("compiled->nocache_hash = '{$this->nocache_hash}';\n?>\n"); } - if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { + if (function_exists('mb_internal_encoding') + && function_exists('ini_get') + && ((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } else { diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 18f9d562c..e35d93619 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -126,7 +126,8 @@ public function process(Smarty_Internal_Template $_smarty_tpl) */ private function loadCompiledTemplate(Smarty_Internal_Template $_smarty_tpl) { - if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) { + if (function_exists('opcache_invalidate') + && (!function_exists('ini_get') || strlen(ini_get("opcache.restrict_api")) < 1)) { opcache_invalidate($this->filepath, true); } elseif (function_exists('apc_compile_file')) { apc_compile_file($this->filepath);