Update CodeIgniter system 3.1.0 => 3.1.16

This commit is contained in:
2020-08-02 02:23:47 -04:00
parent 3523bc5f57
commit 083b534f0a
176 changed files with 2351 additions and 1889 deletions
@@ -6,7 +6,7 @@
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2016, British Columbia Institute of Technology
* Copyright (c) 2014 - 2019, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -29,8 +29,8 @@
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
* @license https://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 3.0.0
* @filesource
@@ -51,7 +51,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
/**
* phpRedis instance
*
* @var resource
* @var Redis
*/
protected $_redis;
@@ -76,6 +76,33 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
*/
protected $_key_exists = FALSE;
/**
* Name of setTimeout() method in phpRedis
*
* Due to some deprecated methods in phpRedis, we need to call the
* specific methods depending on the version of phpRedis.
*
* @var string
*/
protected $_setTimeout_name;
/**
* Name of delete() method in phpRedis
*
* Due to some deprecated methods in phpRedis, we need to call the
* specific methods depending on the version of phpRedis.
*
* @var string
*/
protected $_delete_name;
/**
* Success return value of ping() method in phpRedis
*
* @var mixed
*/
protected $_ping_success;
// ------------------------------------------------------------------------
/**
@@ -88,6 +115,20 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
{
parent::__construct($params);
// Detect the names of some methods in phpRedis instance
if (version_compare(phpversion('redis'), '5', '>='))
{
$this->_setTimeout_name = 'expire';
$this->_delete_name = 'del';
$this->_ping_success = TRUE;
}
else
{
$this->_setTimeout_name = 'setTimeout';
$this->_delete_name = 'delete';
$this->_ping_success = '+PONG';
}
if (empty($this->_config['save_path']))
{
log_message('error', 'Session: No Redis save path configured.');
@@ -131,7 +172,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
{
if (empty($this->_config['save_path']))
{
return $this->_fail();
return $this->_failure;
}
$redis = new Redis();
@@ -150,10 +191,11 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
else
{
$this->_redis = $redis;
$this->php5_validate_id();
return $this->_success;
}
return $this->_fail();
return $this->_failure;
}
// ------------------------------------------------------------------------
@@ -183,7 +225,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
return $session_data;
}
return $this->_fail();
return $this->_failure;
}
// ------------------------------------------------------------------------
@@ -199,43 +241,38 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
*/
public function write($session_id, $session_data)
{
if ( ! isset($this->_redis))
if ( ! isset($this->_redis, $this->_lock_key))
{
return $this->_fail();
return $this->_failure;
}
// Was the ID regenerated?
elseif ($session_id !== $this->_session_id)
{
if ( ! $this->_release_lock() OR ! $this->_get_lock($session_id))
{
return $this->_fail();
return $this->_failure;
}
$this->_key_exists = FALSE;
$this->_session_id = $session_id;
}
if (isset($this->_lock_key))
$this->_redis->{$this->_setTimeout_name}($this->_lock_key, 300);
if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE)
{
$this->_redis->setTimeout($this->_lock_key, 300);
if ($this->_fingerprint !== ($fingerprint = md5($session_data)) OR $this->_key_exists === FALSE)
if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration']))
{
if ($this->_redis->set($this->_key_prefix.$session_id, $session_data, $this->_config['expiration']))
{
$this->_fingerprint = $fingerprint;
$this->_key_exists = TRUE;
return $this->_success;
}
return $this->_fail();
$this->_fingerprint = $fingerprint;
$this->_key_exists = TRUE;
return $this->_success;
}
return ($this->_redis->setTimeout($this->_key_prefix.$session_id, $this->_config['expiration']))
? $this->_success
: $this->_fail();
return $this->_failure;
}
return $this->_fail();
return ($this->_redis->{$this->_setTimeout_name}($this->_key_prefix.$session_id, $this->_config['expiration']))
? $this->_success
: $this->_failure;
}
// ------------------------------------------------------------------------
@@ -252,12 +289,12 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
if (isset($this->_redis))
{
try {
if ($this->_redis->ping() === '+PONG')
if ($this->_redis->ping() === $this->_ping_success)
{
$this->_release_lock();
if ($this->_redis->close() === FALSE)
{
return $this->_fail();
return $this->_failure;
}
}
}
@@ -287,16 +324,16 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
{
if (isset($this->_redis, $this->_lock_key))
{
if (($result = $this->_redis->delete($this->_key_prefix.$session_id)) !== 1)
if (($result = $this->_redis->{$this->_delete_name}($this->_key_prefix.$session_id)) !== 1)
{
log_message('debug', 'Session: Redis::delete() expected to return 1, got '.var_export($result, TRUE).' instead.');
log_message('debug', 'Session: Redis::'.$this->_delete_name.'() expected to return 1, got '.var_export($result, TRUE).' instead.');
}
$this->_cookie_destroy();
return $this->_success;
}
return $this->_fail();
return $this->_failure;
}
// ------------------------------------------------------------------------
@@ -315,6 +352,22 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
return $this->_success;
}
// --------------------------------------------------------------------
/**
* Validate ID
*
* Checks whether a session ID record exists server-side,
* to enforce session.use_strict_mode.
*
* @param string $id
* @return bool
*/
public function validateSessionId($id)
{
return (bool) $this->_redis->exists($this->_key_prefix.$id);
}
// ------------------------------------------------------------------------
/**
@@ -332,7 +385,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
// correct session ID.
if ($this->_lock_key === $this->_key_prefix.$session_id.':lock')
{
return $this->_redis->setTimeout($this->_lock_key, 300);
return $this->_redis->{$this->_setTimeout_name}($this->_lock_key, 300);
}
// 30 attempts to obtain a lock, in case another request already has it
@@ -346,7 +399,13 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
continue;
}
if ( ! $this->_redis->setex($lock_key, 300, time()))
if ($ttl === -2 && ! $this->_redis->set($lock_key, time(), array('nx', 'ex' => 300)))
{
// Sleep for 1s to wait for lock releases.
sleep(1);
continue;
}
elseif ( ! $this->_redis->setex($lock_key, 300, time()))
{
log_message('error', 'Session: Error while trying to obtain lock for '.$this->_key_prefix.$session_id);
return FALSE;
@@ -384,7 +443,7 @@ class CI_Session_redis_driver extends CI_Session_driver implements SessionHandle
{
if (isset($this->_redis, $this->_lock_key) && $this->_lock)
{
if ( ! $this->_redis->delete($this->_lock_key))
if ( ! $this->_redis->{$this->_delete_name}($this->_lock_key))
{
log_message('error', 'Session: Error while trying to free lock for '.$this->_lock_key);
return FALSE;