Skip to content

Commit

Permalink
Do not cache version info in the sessions
Browse files Browse the repository at this point in the history
If the session is cleared and closed for whatever reason the loadVersion
will write to the session anyways. This will lead to an exception.

This should fix #1303

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
  • Loading branch information
rullzer committed Nov 15, 2016
1 parent 571c5aa commit 028c668
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions lib/private/legacy/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class OC_Util {
private static $rootMounted = false;
private static $fsSetup = false;

/** @var array Local cache of version.php */
private static $versionCache = null;

protected static function getAppManager() {
return \OC::$server->getAppManager();
}
Expand Down Expand Up @@ -397,7 +400,7 @@ public static function tearDownFS() {
*/
public static function getVersion() {
OC_Util::loadVersion();
return \OC::$server->getSession()->get('OC_Version');
return self::$versionCache['OC_Version'];
}

/**
Expand All @@ -407,7 +410,7 @@ public static function getVersion() {
*/
public static function getVersionString() {
OC_Util::loadVersion();
return \OC::$server->getSession()->get('OC_VersionString');
return self::$versionCache['OC_VersionString'];
}

/**
Expand All @@ -424,7 +427,7 @@ public static function getEditionString() {
*/
public static function getChannel() {
OC_Util::loadVersion();
return \OC::$server->getSession()->get('OC_Channel');
return self::$versionCache['OC_Channel'];
}

/**
Expand All @@ -433,41 +436,41 @@ public static function getChannel() {
*/
public static function getBuild() {
OC_Util::loadVersion();
return \OC::$server->getSession()->get('OC_Build');
return self::$versionCache['OC_Build'];
}

/**
* @description load the version.php into the session as cache
*/
private static function loadVersion() {
if (self::$versionCache !== null) {
return;
}

$timestamp = filemtime(OC::$SERVERROOT . '/version.php');
if (!\OC::$server->getSession()->exists('OC_Version') or OC::$server->getSession()->get('OC_Version_Timestamp') != $timestamp) {
require OC::$SERVERROOT . '/version.php';
$session = \OC::$server->getSession();
/** @var $timestamp int */
$session->set('OC_Version_Timestamp', $timestamp);
/** @var $OC_Version string */
$session->set('OC_Version', $OC_Version);
/** @var $OC_VersionString string */
$session->set('OC_VersionString', $OC_VersionString);
/** @var $OC_Build string */
$session->set('OC_Build', $OC_Build);

// Allow overriding update channel
require OC::$SERVERROOT . '/version.php';
/** @var $timestamp int */
self::$versionCache['OC_Version_Timestamp'] = $timestamp;
/** @var $OC_Version string */
self::$versionCache['OC_Version'] = $OC_Version;
/** @var $OC_VersionString string */
self::$versionCache['OC_VersionString'] = $OC_VersionString;
/** @var $OC_Build string */
self::$versionCache['OC_Build'] = $OC_Build;

if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
$channel = \OC::$server->getAppConfig()->getValue('core', 'OC_Channel');
} else {
/** @var $OC_Channel string */
$channel = $OC_Channel;
}
// Allow overriding update channel
if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
$channel = \OC::$server->getAppConfig()->getValue('core', 'OC_Channel');
} else {
/** @var $OC_Channel string */
$channel = $OC_Channel;
}

if (!is_null($channel)) {
$session->set('OC_Channel', $channel);
} else {
/** @var $OC_Channel string */
$session->set('OC_Channel', $OC_Channel);
}
if (!is_null($channel)) {
self::$versionCache['OC_Channel'] = $channel;
} else {
/** @var $OC_Channel string */
self::$versionCache['OC_Channel'] = $OC_Channel;
}
}

Expand Down

0 comments on commit 028c668

Please sign in to comment.