Skip to content

Commit ff53d0a

Browse files
committed
fix(share): Avoid crash when share owner is not found
IShare::getNode is documented to throw only NotFoundException, so catch UserNotFoundException from the level below and wrap it. This avoids crashes from share api controller when listing shares and one of them is broken because its owner has vanished from the backend. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent b3004aa commit ff53d0a

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

lib/private/Share20/Share.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\Share\IAttributes;
2222
use OCP\Share\IManager;
2323
use OCP\Share\IShare;
24+
use OCP\User\Exceptions\UserNotFoundException;
2425
use Override;
2526

2627
class Share implements IShare {
@@ -135,20 +136,24 @@ public function getNode(): Node {
135136
throw new NotFoundException();
136137
}
137138

138-
// for federated shares the owner can be a remote user, in this
139-
// case we use the initiator
140-
if ($this->userManager->userExists($this->shareOwner)) {
141-
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
142-
} else {
143-
$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
144-
}
145-
146-
$node = $userFolder->getFirstNodeById($this->fileId);
147-
if (!$node) {
148-
throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
139+
try {
140+
// for federated shares the owner can be a remote user, in this
141+
// case we use the initiator
142+
if ($this->userManager->userExists($this->shareOwner)) {
143+
$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
144+
} else {
145+
$userFolder = $this->rootFolder->getUserFolder($this->sharedBy);
146+
}
147+
148+
$node = $userFolder->getFirstNodeById($this->fileId);
149+
if (!$node) {
150+
throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId);
151+
}
152+
153+
$this->node = $node;
154+
} catch (UserNotFoundException $e) {
155+
throw new NotFoundException('Owner for share not found, fileid: ' . $this->fileId, previous:$e);
149156
}
150-
151-
$this->node = $node;
152157
}
153158

154159
return $this->node;

0 commit comments

Comments
 (0)