From c4efe4eeaf591c57591815f4ceb9bedbfbd03d5f Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 12 Apr 2019 17:00:48 +0200 Subject: [PATCH] Throw an error when trying to use the user storage for guests Closes #2888 --- .../user/storage/UserStorageHandler.class.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php b/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php index 2c8c2e7f02..b2e75606a2 100644 --- a/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/storage/UserStorageHandler.class.php @@ -56,6 +56,8 @@ class UserStorageHandler extends SingletonFactory { * @param integer[] $userIDs */ public function loadStorage(array $userIDs) { + $this->validateUserIDs($userIDs); + if ($this->redis) return; $tmp = []; @@ -91,6 +93,8 @@ class UserStorageHandler extends SingletonFactory { * @return mixed[] */ public function getStorage(array $userIDs, $field) { + $this->validateUserIDs($userIDs); + $data = []; if ($this->redis) { @@ -161,6 +165,8 @@ class UserStorageHandler extends SingletonFactory { * @param string $fieldValue */ public function update($userID, $field, $fieldValue) { + $this->validateUserIDs([$userID]); + if ($this->redis) { $this->redis->hSet($this->getRedisFieldName($field), $userID, $fieldValue); $this->redis->expire($this->getRedisFieldName($field), 86400); @@ -182,6 +188,8 @@ class UserStorageHandler extends SingletonFactory { * @param string $field */ public function reset(array $userIDs, $field) { + $this->validateUserIDs($userIDs); + if ($this->redis) { foreach ($userIDs as $userID) { $this->redis->hDel($this->getRedisFieldName($field), $userID); @@ -352,4 +360,16 @@ class UserStorageHandler extends SingletonFactory { return 'ush:'.$flush.':'.$fieldName; } + + /** + * @param int[] $userIDs + * @since 5.2 + */ + protected function validateUserIDs(array $userIDs) { + foreach ($userIDs as $userID) { + if (!$userID) { + throw new \InvalidArgumentException('The user id can neither be null nor zero.'); + } + } + } } -- 2.20.1