Skip to content

Commit 3fb40e5

Browse files
author
Marius Burkard
committed
- prevent undefined var in loop count for tpl lib
1 parent 0b6c055 commit 3fb40e5

File tree

4 files changed

+52
-29
lines changed

4 files changed

+52
-29
lines changed

install/lib/classes/tpl.inc.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,12 +931,17 @@ private function _parseLoop ($varname)
931931
{
932932
array_push($this->_namespace, $varname);
933933
$tempvar = count($this->_namespace) - 1;
934-
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < count(\$this->_arrvars";
934+
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars";
935935
for ($i=0; $i < count($this->_namespace); $i++) {
936936
$retstr .= "['".$this->_namespace[$i]."']";
937937
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
938938
}
939-
return $retstr."); \$_".$tempvar."++) {";
939+
$retstr .= ") ? count(\$this->_arrvars";
940+
for ($i=0; $i < count($this->_namespace); $i++) {
941+
$retstr .= "['".$this->_namespace[$i]."']";
942+
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
943+
}
944+
return $retstr.") : 0); \$_".$tempvar."++) {";
940945
}
941946

942947
/**
@@ -1035,7 +1040,7 @@ private function _parseTag ($args)
10351040
$wholetag = $args[0];
10361041
$openclose = $args[1];
10371042
$tag = strtolower($args[2]);
1038-
1043+
10391044
if ($tag == 'else') return '<?php } else { ?>';
10401045
if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags
10411046

@@ -1170,7 +1175,15 @@ private function _parse ($compress = '')
11701175

11711176
array_push($this->_currentincludedir, dirname($this->_tmplfilename));
11721177
$this->_includedepth++;
1173-
$success = @eval($this->_tmplfilep);
1178+
try {
1179+
$success = @eval($this->_tmplfilep);
1180+
} catch(Exception $ex) {
1181+
print $this->_tmplfilep;
1182+
throw $ex;
1183+
} catch(TypeError $ex) {
1184+
print $this->_tmplfilep;
1185+
throw $ex;
1186+
}
11741187
$this->_includedepth--;
11751188
array_pop($this->_currentincludedir);
11761189

install/lib/installer_base.lib.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,10 +1914,10 @@ public function configure_rspamd() {
19141914
}
19151915

19161916
$tpl->setVar('dkim_path', $mail_config['dkim_path']);
1917-
$tpl->setVar('rspamd_redis_servers', $mail_config['rspamd_redis_servers']);
1918-
$tpl->setVar('rspamd_redis_password', $mail_config['rspamd_redis_password']);
1919-
$tpl->setVar('rspamd_redis_bayes_servers', $mail_config['rspamd_redis_bayes_servers']);
1920-
$tpl->setVar('rspamd_redis_bayes_password', $mail_config['rspamd_redis_bayes_password']);
1917+
$tpl->setVar('rspamd_redis_servers', (isset($mail_config['rspamd_redis_servers']) ? $mail_config['rspamd_redis_servers'] : ''));
1918+
$tpl->setVar('rspamd_redis_password', (isset($mail_config['rspamd_redis_password']) ? $mail_config['rspamd_redis_password'] : ''));
1919+
$tpl->setVar('rspamd_redis_bayes_servers', (isset($mail_config['rspamd_redis_bayes_servers']) ? $mail_config['rspamd_redis_bayes_servers'] : ''));
1920+
$tpl->setVar('rspamd_redis_bayes_password', (isset($mail_config['rspamd_redis_bayes_password']) ? $mail_config['rspamd_redis_bayes_password'] : ''));
19211921
if(count($local_addrs) > 0) {
19221922
$tpl->setLoop('local_addrs', $local_addrs);
19231923
}

interface/lib/classes/tpl.inc.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function newTemplate($tmplfile)
233233
public function setVar($k, $v = null, $encode = false)
234234
{
235235
global $app;
236-
236+
237237
if (is_array($k)) {
238238
foreach($k as $key => $value){
239239
$key = ($this->OPTIONS['CASELESS']) ? strtolower(trim($key)) : trim($key);
@@ -1079,12 +1079,12 @@ private function _parseIf($varname, $value = null, $op = null, $namespace = null
10791079
private function _parseHook ($name)
10801080
{
10811081
global $app;
1082-
1082+
10831083
if(!$name) return false;
1084-
1084+
10851085
$module = isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : '';
10861086
$form = isset($app->tform->formDef['name']) ? $app->tform->formDef['name'] : '';
1087-
1087+
10881088
$events = array();
10891089
if($module) {
10901090
$events[] = $module . ':' . ($form ? $form : '') . ':' . $name;
@@ -1093,9 +1093,9 @@ private function _parseHook ($name)
10931093
$events[] = $name;
10941094
$events[] = 'on_template_content';
10951095
}
1096-
1096+
10971097
$events = array_unique($events);
1098-
1098+
10991099
for($e = 0; $e < count($events); $e++) {
11001100
$tmpresult = $app->plugin->raiseEvent($events[$e], array(
11011101
'name' => $name,
@@ -1104,10 +1104,10 @@ private function _parseHook ($name)
11041104
), true);
11051105
if(!$tmpresult) $tmpresult = '';
11061106
else $tmpresult = $this->_getData($tmpresult, false, true);
1107-
1107+
11081108
$result .= $tmpresult;
11091109
}
1110-
1110+
11111111
return $result;
11121112
}
11131113

@@ -1121,12 +1121,17 @@ private function _parseLoop ($varname)
11211121
{
11221122
array_push($this->_namespace, $varname);
11231123
$tempvar = count($this->_namespace) - 1;
1124-
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < count(\$this->_arrvars";
1124+
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars";
11251125
for ($i=0; $i < count($this->_namespace); $i++) {
11261126
$retstr .= "['".$this->_namespace[$i]."']";
11271127
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
11281128
}
1129-
return $retstr."); \$_".$tempvar."++) {";
1129+
$retstr .= ") ? count(\$this->_arrvars";
1130+
for ($i=0; $i < count($this->_namespace); $i++) {
1131+
$retstr .= "['".$this->_namespace[$i]."']";
1132+
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
1133+
}
1134+
return $retstr.") : 0); \$_".$tempvar."++) {";
11301135
}
11311136

11321137
/**
@@ -1225,7 +1230,7 @@ private function _parseTag ($args)
12251230
$wholetag = $args[0];
12261231
$openclose = $args[1];
12271232
$tag = strtolower($args[2]);
1228-
1233+
12291234
if ($tag == 'else') return '<?php } else { ?>';
12301235
if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags
12311236

@@ -1303,10 +1308,10 @@ private function _parseTag ($args)
13031308
if ($this->OPTIONS['ENABLE_PHPINCLUDE']) {
13041309
return '<?php include(\''.$file.'\'); ?>';
13051310
}
1306-
1311+
13071312
case 'hook':
13081313
return $this->_parseHook(@$var);
1309-
1314+
13101315
case 'include':
13111316
return '<?php $this->_getData($this->_fileSearch(\''.$file.'\'), 1); ?>';
13121317

server/lib/classes/tpl.inc.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,18 +1074,18 @@ private function _parseIf($varname, $value = null, $op = null, $namespace = null
10741074
private function _parseHook ($name)
10751075
{
10761076
global $app;
1077-
1077+
10781078
$namespace = '';
10791079
if(strpos($name, ':') !== false) list($namespace, $name) = explode(':', $name, 2);
1080-
1080+
10811081
$result = $app->plugins->raiseAction('on_template_content_hook', array(
10821082
'name' => $name,
10831083
'namespace' => $namespace,
10841084
'vars' => $this->_vars
10851085
), true);
10861086
if(!$result) $result = '';
10871087
else $result = $this->_getData($result, false, true);
1088-
1088+
10891089
return $result;
10901090
}
10911091

@@ -1099,12 +1099,17 @@ private function _parseLoop ($varname)
10991099
{
11001100
array_push($this->_namespace, $varname);
11011101
$tempvar = count($this->_namespace) - 1;
1102-
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < count(\$this->_arrvars";
1102+
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars";
1103+
for ($i=0; $i < count($this->_namespace); $i++) {
1104+
$retstr .= "['".$this->_namespace[$i]."']";
1105+
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
1106+
}
1107+
$retstr .= ") ? count(\$this->_arrvars";
11031108
for ($i=0; $i < count($this->_namespace); $i++) {
11041109
$retstr .= "['".$this->_namespace[$i]."']";
11051110
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
11061111
}
1107-
return $retstr."); \$_".$tempvar."++) {";
1112+
return $retstr.") : 0); \$_".$tempvar."++) {";
11081113
}
11091114

11101115
/**
@@ -1203,7 +1208,7 @@ private function _parseTag ($args)
12031208
$wholetag = $args[0];
12041209
$openclose = $args[1];
12051210
$tag = strtolower($args[2]);
1206-
1211+
12071212
if ($tag == 'else') return '<?php } else { ?>';
12081213
if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags
12091214

@@ -1281,10 +1286,10 @@ private function _parseTag ($args)
12811286
if ($this->OPTIONS['ENABLE_PHPINCLUDE']) {
12821287
return '<?php include(\''.$file.'\'); ?>';
12831288
}
1284-
1289+
12851290
case 'hook':
12861291
return $this->_parseHook(@$var);
1287-
1292+
12881293
case 'include':
12891294
return '<?php $this->_getData($this->_fileSearch(\''.$file.'\'), 1); ?>';
12901295

0 commit comments

Comments
 (0)