diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-05-31 12:15:06 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2017-06-15 11:20:49 +0200 |
commit | d1a8269de31ffa85ff7908c31f3c270b76be361c (patch) | |
tree | 579242a7fe31d750c87e181f3e5d3be8cf3119a1 /lib/private/Session | |
parent | ca3c69c8ae0fd7f0d13e87d7861c54e2950a2c09 (diff) | |
download | nextcloud-server-d1a8269de31ffa85ff7908c31f3c270b76be361c.tar.gz nextcloud-server-d1a8269de31ffa85ff7908c31f3c270b76be361c.zip |
Forward port of #5190 to master
Treat PHP Errors on User session regenerate
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
remove unnecessary lines…
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
change PHP errors to ErrorException in the session (PHP >=7)
Otherwise it might be that authentication apps are being disabled on
during operation while in fact the session handler has hiccup.
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'lib/private/Session')
-rw-r--r-- | lib/private/Session/Internal.php | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/lib/private/Session/Internal.php b/lib/private/Session/Internal.php index 72af5727a54..09b33f79d29 100644 --- a/lib/private/Session/Internal.php +++ b/lib/private/Session/Internal.php @@ -43,12 +43,12 @@ class Internal extends Session { * @throws \Exception */ public function __construct($name) { - session_name($name); set_error_handler(array($this, 'trapError')); + $this->invoke('session_name', [$name]); try { - session_start(); + $this->invoke('session_start'); } catch (\Exception $e) { - setcookie(session_name(), null, -1, \OC::$WEBROOT ? : '/'); + setcookie($this->invoke('session_name'), null, -1, \OC::$WEBROOT ?: '/'); } restore_error_handler(); if (!isset($_SESSION)) { @@ -94,14 +94,14 @@ class Internal extends Session { } public function clear() { - session_unset(); + $this->invoke('session_unset'); $this->regenerateId(); - @session_start(); - $_SESSION = array(); + $this->invoke('session_start', [], true); + $_SESSION = []; } public function close() { - session_write_close(); + $this->invoke('session_write_close'); parent::close(); } @@ -112,7 +112,11 @@ class Internal extends Session { * @return void */ public function regenerateId($deleteOldSession = true) { - @session_regenerate_id($deleteOldSession); + try { + @session_regenerate_id($deleteOldSession); + } catch (\Error $e) { + $this->trapError($e->getCode(), $e->getMessage()); + } } /** @@ -123,7 +127,7 @@ class Internal extends Session { * @since 9.1.0 */ public function getId() { - $id = @session_id(); + $id = $this->invoke('session_id', [], true); if ($id === '') { throw new SessionNotAvailableException(); } @@ -154,4 +158,23 @@ class Internal extends Session { throw new SessionNotAvailableException('Session has been closed - no further changes to the session are allowed'); } } + + /** + * @param string $functionName the full session_* function name + * @param array $parameters + * @param bool $silence whether to suppress warnings + * @throws \ErrorException via trapError + * @return mixed + */ + private function invoke($functionName, array $parameters = [], $silence = false) { + try { + if($silence) { + return @call_user_func_array($functionName, $parameters); + } else { + return call_user_func_array($functionName, $parameters); + } + } catch(\Error $e) { + $this->trapError($e->getCode(), $e->getMessage()); + } + } } |