Skip to content

Commit

Permalink
Check the return value of getUserSession before using it
Browse files Browse the repository at this point in the history
Checking if the value returned by getUserSession
and getUser is null or not before using it.

Signed-off-by: Sujith H <sharidasan@owncloud.com>
  • Loading branch information
sharidas committed Feb 8, 2018
1 parent 10327d5 commit 8bdfe3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 10 additions & 6 deletions lib/private/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use InterfaSys\LogNormalizer\Normalizer;

use \OCP\ILogger;
use OCP\IUserSession;
use OCP\Util;

/**
Expand Down Expand Up @@ -292,12 +293,15 @@ public function log($level, $message, array $context = []) {

// check for user
if (!empty($logCondition['users'])) {
$user = \OC::$server->getUserSession()->getUser();

// if the user matches set the log condition to satisfied
if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) {
$this->logConditionSatisfied = true;
break;
$userSession = \OC::$server->getUserSession();
if ($userSession instanceof IUserSession) {
$user = $userSession->getUser();

// if the user matches set the log condition to satisfied
if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) {
$this->logConditionSatisfied = true;
break;
}
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,12 @@ public function canChangePassword() {
*/
public function canChangeDisplayName() {
// Only Admin and SubAdmins are allowed to change display name
if (($this->config->getSystemValue('allow_user_to_change_display_name') === false) &&
(!$this->groupManager->isAdmin($this->userSession->getUser()->getUID())) &&
(!$this->groupManager->getSubAdmin()->isSubAdmin($this->userSession->getUser()))) {
$user = $this->userSession->getUser();
if (
($this->config->getSystemValue('allow_user_to_change_display_name') === false) &&
(($user !== null) && (!$this->groupManager->isAdmin($user->getUID()))) &&
(($user !== null) && (!$this->groupManager->getSubAdmin()->isSubAdmin($user)))
) {
return false;
}
$backend = $this->account->getBackendInstance();
Expand Down

0 comments on commit 8bdfe3f

Please sign in to comment.