Skip to content

Commit

Permalink
Protect group share updates with transaction
Browse files Browse the repository at this point in the history
To avoid race conditions happening exactly between the select and
insert/update.
  • Loading branch information
Vincent Petry committed Mar 15, 2019
1 parent c146ac5 commit 32d622f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ public function updateForRecipient(\OCP\Share\IShare $share, $recipient) {
throw new ProviderException('Recipient not in receiving group');
}

// using transaction to prevent concurrent updates
$this->dbConn->beginTransaction();

// Check if there is a usergroup share
$qb = $this->dbConn->getQueryBuilder();
$stmt = $qb->select('id')
Expand Down Expand Up @@ -424,6 +427,8 @@ public function updateForRecipient(\OCP\Share\IShare $share, $recipient) {
->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
->execute();
}

$this->dbConn->commit();
} else {
throw new ProviderException('Can\'t update share of recipient for share type ' . $share->getShareType());
}
Expand Down

0 comments on commit 32d622f

Please sign in to comment.