Skip to content

Commit cce3dfd

Browse files
Merge pull request #62960 from nextcloud/backport/62798/stable33
[stable33] fix(share): Avoid crash when share owner is not found
2 parents b6863b6 + f5e94a3 commit cce3dfd

1 file changed

Lines changed: 19 additions & 13 deletions

File tree

lib/private/Share20/Share.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
66
* SPDX-License-Identifier: AGPL-3.0-only
77
*/
8+
89
namespace OC\Share20;
910

11+
use OC\User\NoUserException;
1012
use OCP\Constants;
1113
use OCP\Files\Cache\ICacheEntry;
1214
use OCP\Files\File;
@@ -158,20 +160,24 @@ public function getNode() {
158160
throw new NotFoundException();
159161
}
160162

161-
// for federated shares the owner can be a remote user, in this
162-
// case we use the initiator
163-
if ($this->userManager->userExists($this->shareOwner)) {
164-
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
165-
} else {
166-
$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
163+
try {
164+
// for federated shares the owner can be a remote user, in this
165+
// case we use the initiator
166+
if ($this->userManager->userExists($this->shareOwner)) {
167+
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
168+
} else {
169+
$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
170+
}
171+
172+
$node = $userFolder->getFirstNodeById($this->fileId);
173+
if (!$node) {
174+
throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
175+
}
176+
177+
$this->node = $node;
178+
} catch (NoUserException $e) {
179+
throw new NotFoundException('Owner for share not found, fileid: ' . $this->fileId, previous:$e);
167180
}
168-
169-
$node = $userFolder->getFirstNodeById($this->fileId);
170-
if (!$node) {
171-
throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
172-
}
173-
174-
$this->node = $node;
175181
}
176182

177183
return $this->node;

0 commit comments

Comments
 (0)