From e8615cf494302f80aa9e8a36a280aa5cb8e3742a Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 04 Sep 2012 08:42:13 -0400
Subject: [PATCH] Merge pull request #25 from raoulbhatia/fix-1488669
---
program/include/rcube_session.php | 50 +++++++++++++++++++++++++++++---------------------
1 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/program/include/rcube_session.php b/program/include/rcube_session.php
index 53042b3..e00401f 100644
--- a/program/include/rcube_session.php
+++ b/program/include/rcube_session.php
@@ -40,7 +40,7 @@
private $unsets = array();
private $gc_handlers = array();
private $cookiename = 'roundcube_sessauth';
- private $vars = false;
+ private $vars;
private $key;
private $now;
private $secret = '';
@@ -137,11 +137,10 @@
$this->vars = base64_decode($sql_arr['vars']);
$this->key = $key;
- if (!empty($this->vars))
- return $this->vars;
+ return !empty($this->vars) ? (string) $this->vars : '';
}
- return false;
+ return null;
}
@@ -160,7 +159,7 @@
// no session row in DB (db_read() returns false)
if (!$this->key) {
- $oldvars = false;
+ $oldvars = null;
}
// use internal data from read() for fast requests (up to 0.5 sec.)
else if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) {
@@ -170,7 +169,7 @@
$oldvars = $this->db_read($key);
}
- if ($oldvars !== false) {
+ if ($oldvars !== null) {
$newvars = $this->_fixvars($vars, $oldvars);
if ($newvars !== $oldvars) {
@@ -200,7 +199,7 @@
*/
private function _fixvars($vars, $oldvars)
{
- if ($oldvars !== false) {
+ if ($oldvars !== null) {
$a_oldvars = $this->unserialize($oldvars);
if (is_array($a_oldvars)) {
foreach ((array)$this->unsets as $k)
@@ -222,13 +221,14 @@
* Handler for session_destroy()
*
* @param string Session ID
+ *
* @return boolean True on success
*/
public function db_destroy($key)
{
- $this->db->query(
- sprintf("DELETE FROM %s WHERE sess_id = ?", get_table_name('session')),
- $key);
+ if ($key) {
+ $this->db->query(sprintf("DELETE FROM %s WHERE sess_id = ?", get_table_name('session')), $key);
+ }
return true;
}
@@ -268,12 +268,12 @@
$this->vars = $arr['vars'];
$this->key = $key;
- if (!empty($this->vars))
- return $this->vars;
+ return !empty($this->vars) ? (string) $this->vars : '';
}
- return false;
+ return null;
}
+
/**
* Save session data.
@@ -289,30 +289,37 @@
// no session data in cache (mc_read() returns false)
if (!$this->key)
- $oldvars = false;
+ $oldvars = null;
// use internal data for fast requests (up to 0.5 sec.)
else if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5))
$oldvars = $this->vars;
else // else read data again
$oldvars = $this->mc_read($key);
- $newvars = $oldvars !== false ? $this->_fixvars($vars, $oldvars) : $vars;
-
+ $newvars = $oldvars !== null ? $this->_fixvars($vars, $oldvars) : $vars;
+
if ($newvars !== $oldvars || $ts - $this->changed > $this->lifetime / 2)
return $this->memcache->set($key, serialize(array('changed' => time(), 'ip' => $this->ip, 'vars' => $newvars)), MEMCACHE_COMPRESSED, $this->lifetime);
-
+
return true;
}
+
/**
* Handler for session_destroy() with memcache backend
*
* @param string Session ID
+ *
* @return boolean True on success
*/
public function mc_destroy($key)
{
- return $this->memcache->delete($key);
+ if ($key) {
+ // #1488592: use 2nd argument
+ $this->memcache->delete($key, 0);
+ }
+
+ return true;
}
@@ -352,7 +359,7 @@
{
session_regenerate_id($destroy);
- $this->vars = false;
+ $this->vars = null;
$this->key = session_id();
return true;
@@ -375,13 +382,14 @@
return true;
}
-
+
+
/**
* Kill this session
*/
public function kill()
{
- $this->vars = false;
+ $this->vars = null;
$this->ip = $_SERVER['REMOTE_ADDR']; // update IP (might have changed)
$this->destroy(session_id());
rcmail::setcookie($this->cookiename, '-del-', time() - 60);
--
Gitblit v1.9.1