Emergency template not necessarily called

A place to report and discuss bugs - please mention CMSimple-version, server, platform and browser version
Post Reply
cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Emergency template not necessarily called

Post by cmb » Sun Mar 08, 2015 1:05 am

Hello Community,

Ludwig found a bug in CMSimple_XH, where a missing template can "randomly" cause a white screen (no 500 Internal Server Error, though). The bug was introduced with XH 1.6 where locking of the template during reading was implemented. The relevant code (cmsimple/cms.php) is:

Code: Select all

$temp = fopen($pth['file']['template'], 'r');
if ($temp) {
    if (XH_lockFile($temp, LOCK_SH)) {
        $i = include $pth['file']['template'];
        XH_lockFile($temp, LOCK_UN);
    }
    fclose($temp);
}
if (!$i) {// the template could not be included           
When the template does not exist, $temp is falsey, so $i has an undetermined value, because $i is a temporary global variable.

The bugfix is straight forward: just initialize $i = false right before the code (done: r1501/r1502) .

BTW: it would be nice if we could put the code in a function/method (say, renderTemplate()), but that would be somewhat ugly, because the template usually accesses global variables so these would have to be "imported" in the function/method. It's possible with PHP, as can be seen in evaluate_cmsimple_scripting(), but it's a hack. Not sure, if we should do it.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply