From b8c61b3515ef406c4feafc851f12262e417ba157 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 1 Jun 2023 20:19:24 +0200 Subject: fix(caching): Avoid checking existence before fetching The cache might expire between checking for key existence and fetching the value. In this rare case the code continues with a null value when it doesn't expect one. Signed-off-by: Christoph Wurst --- lib/private/Accounts/AccountManager.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 60065272a58..e3068a7ff25 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -795,8 +795,9 @@ class AccountManager implements IAccountManager { } public function getAccount(IUser $user): IAccount { - if ($this->internalCache->hasKey($user->getUID())) { - return $this->internalCache->get($user->getUID()); + $cached = $this->internalCache->get($user->getUID()); + if ($cached !== null) { + return $cached; } $account = $this->parseAccountData($user, $this->getUser($user)); $this->internalCache->set($user->getUID(), $account); -- cgit v1.2.3