Skip to content

Commit

Permalink
Sandbox: Keep security tokens alive in canAccess methods
Browse files Browse the repository at this point in the history
This fixes a regression introduced in 5111af7
and the corresponding issues (mixxxdj#11552 and mixxxdj#12137).

To prevent this from happening again, 8c6154e
marks `openSecurityToken` as `[[nodiscard]]`.
  • Loading branch information
fwcd committed Dec 22, 2023
1 parent 8c6154e commit 94b5a11
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/util/sandbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ bool Sandbox::canAccess(mixxx::FileInfo* pFileInfo) {
VERIFY_OR_DEBUG_ASSERT(pFileInfo) {
return false;
}
openSecurityToken(pFileInfo, true);
// NOTE: The token must be assigned to a variable, otherwise it will be
// invalidated immediately (causing `isReadable` to fail).
auto token = openSecurityToken(pFileInfo, true);
return pFileInfo->isReadable();
}

//static
bool Sandbox::canAccessDir(const QDir& dir) {
openSecurityTokenForDir(dir, true);
// NOTE: The token must be assigned to a variable, otherwise it will be
// invalidated immediately (causing `isReadable` to fail).
auto token = openSecurityTokenForDir(dir, true);
return QFileInfo(dir.canonicalPath()).isReadable();
}

Expand Down

0 comments on commit 94b5a11

Please sign in to comment.