Bug 1693541 - Improve uses of nsBaseHashtable and descendants and avoid multiple subsequent lookups in security/sandbox/linux/broker. r=jld

Differential Revision: https://phabricator.services.mozilla.com/D106116
This commit is contained in:
Simon Giesecke 2021-03-10 10:37:05 +00:00
Родитель b33a0c377a
Коммит eefee48405
1 изменённых файлов: 9 добавлений и 16 удалений

Просмотреть файл

@ -147,23 +147,19 @@ void SandboxBroker::Policy::AddPath(int aPerms, const char* aPath,
AddCondition aCond) { AddCondition aCond) {
nsDependentCString path(aPath); nsDependentCString path(aPath);
MOZ_ASSERT(path.Length() <= kMaxPathLen); MOZ_ASSERT(path.Length() <= kMaxPathLen);
int perms;
if (aCond == AddIfExistsNow) { if (aCond == AddIfExistsNow) {
struct stat statBuf; struct stat statBuf;
if (lstat(aPath, &statBuf) != 0) { if (lstat(aPath, &statBuf) != 0) {
return; return;
} }
} }
if (!mMap.Get(path, &perms)) { auto& perms = mMap.LookupOrInsert(path, MAY_ACCESS);
perms = MAY_ACCESS; MOZ_ASSERT(perms & MAY_ACCESS);
} else {
MOZ_ASSERT(perms & MAY_ACCESS);
}
if (SandboxInfo::Get().Test(SandboxInfo::kVerbose)) { if (SandboxInfo::Get().Test(SandboxInfo::kVerbose)) {
SANDBOX_LOG_ERROR("policy for %s: %d -> %d", aPath, perms, perms | aPerms); SANDBOX_LOG_ERROR("policy for %s: %d -> %d", aPath, perms, perms | aPerms);
} }
perms |= aPerms; perms |= aPerms;
mMap.InsertOrUpdate(path, perms);
} }
void SandboxBroker::Policy::AddTree(int aPerms, const char* aPath) { void SandboxBroker::Policy::AddTree(int aPerms, const char* aPath) {
@ -229,18 +225,15 @@ void SandboxBroker::Policy::AddPrefix(int aPerms, const char* aPath) {
void SandboxBroker::Policy::AddPrefixInternal(int aPerms, void SandboxBroker::Policy::AddPrefixInternal(int aPerms,
const nsACString& aPath) { const nsACString& aPath) {
int origPerms; auto& perms = mMap.LookupOrInsert(aPath, MAY_ACCESS);
if (!mMap.Get(aPath, &origPerms)) { MOZ_ASSERT(perms & MAY_ACCESS);
origPerms = MAY_ACCESS;
} else { int newPerms = perms | aPerms | RECURSIVE;
MOZ_ASSERT(origPerms & MAY_ACCESS);
}
int newPerms = origPerms | aPerms | RECURSIVE;
if (SandboxInfo::Get().Test(SandboxInfo::kVerbose)) { if (SandboxInfo::Get().Test(SandboxInfo::kVerbose)) {
SANDBOX_LOG_ERROR("policy for %s: %d -> %d", SANDBOX_LOG_ERROR("policy for %s: %d -> %d",
PromiseFlatCString(aPath).get(), origPerms, newPerms); PromiseFlatCString(aPath).get(), perms, newPerms);
} }
mMap.InsertOrUpdate(aPath, newPerms); perms = newPerms;
} }
void SandboxBroker::Policy::AddFilePrefix(int aPerms, const char* aDir, void SandboxBroker::Policy::AddFilePrefix(int aPerms, const char* aDir,