Zen Cart Logo
Forums / Bug Reports / New Version Available code doesn't handle error return from getProjectVersion

New Version Available code doesn't handle error return from getProjectVersion

Views: 1,483

Results 1 to 4 of 4
14 Apr 2018, 12:35 AM
#1
dennisns7d avatar

dennisns7d

New Zenner

Join Date:
Jan 2010
Posts:
55
Plugin Contributions:
0

New Version Available code doesn't handle error return from getProjectVersion

In order to avoid the behavior reported in New Version Available: v{.{ :: {, when error information is returned by getProjectVersion() the code in admin/includes/header.php should display the error information instead of attempting to extract and display version information. This would be an immense help when CURL is not configured properly.

14 Apr 2018, 5:38 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: New Version Available code doesn't handle error return from getProjectVersion

dennisns7d:

In order to avoid the behavior reported in New Version Available: v{.{ :: {, when error information is returned by getProjectVersion() the code in admin/includes/header.php should display the error information instead of attempting to extract and display version information. This would be an immense help when CURL is not configured properly.

What error information was provided that could be evaluated to support the requested action?

14 Apr 2018, 7:01 PM
#3
dennisns7d avatar

dennisns7d

New Zenner

Join Date:
Jan 2010
Posts:
55
Plugin Contributions:
0

Re: New Version Available code doesn't handle error return from getProjectVersion

I've done a bit more digging into the code and determined that the code in admin/includes/header.php is expecting getProjectVersion() to always return an array. The code in admin/includes/classes/VersionServer.php returns a string in the event of a CURL error. To correct this, change line 46 of admin/includes/classes/VersionServer.php from

            return $this->formatCurlError($errno, $error);

to

            return json_decode($this->formatCurlError($errno, $error), true);

To avoid incorrectly reporting that the version is current when in reality a CURL error was encountered, change lines 89-95 of admin/includes/header.php from

    if (isset($newinfo['error'])) {
        $isCurrent = true;
        $versionCheckError = true;
    } else {
        $isCurrent = $versionServer->isProjectCurrent($newinfo);
    }

to ```
if (isset($newinfo['error'])) {
$isCurrent = true;
$versionCheckError = true;
$new_version = '';
} else {
$isCurrent = $versionServer->isProjectCurrent($newinfo);
}


I found it strange to not report the error unless a version check was specifically requested via the vcheck flag was set, so I changed line 121 of admin/includes/header.php from

if (!$doVersionCheck || ($versionCheckError && $version_check_requested == true)) {

to

if (!$doVersionCheck || $versionCheckError) {


With these changes, a CURL error will result in 'Error: Could not contact Project Version Server' being displayed instead of 'v{.{ :: {';
14 Apr 2018, 7:26 PM
#4
dennisns7d avatar

dennisns7d

New Zenner

Join Date:
Jan 2010
Posts:
55
Plugin Contributions:
0

Re: New Version Available code doesn't handle error return from getProjectVersion

To display the CURL error information, change the code in near line 125 from

    if ($versionCheckError) {
        $new_version = ERROR_CONTACTING_PROJECT_VERSION_SERVER . '<br>';
    }

to

    if ($versionCheckError) {
        $new_version = ERROR_CONTACTING_PROJECT_VERSION_SERVER . '<br>' . $newinfo['error'] . '<br>';
    }

In my test case, the CURL error information is 'SSL certificate problem: self signed certificate in certificate chain[60]'. Configuring PHP to use a cacert.pem file cures this particular problem.