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) {
nsDependentCString path(aPath);
MOZ_ASSERT(path.Length() <= kMaxPathLen);
int perms;
if (aCond == AddIfExistsNow) {
struct stat statBuf;
if (lstat(aPath, &statBuf) != 0) {
return;
}
}
if (!mMap.Get(path, &perms)) {
perms = MAY_ACCESS;
} else {
MOZ_ASSERT(perms & MAY_ACCESS);
}
auto& perms = mMap.LookupOrInsert(path, MAY_ACCESS);
MOZ_ASSERT(perms & MAY_ACCESS);
if (SandboxInfo::Get().Test(SandboxInfo::kVerbose)) {
SANDBOX_LOG_ERROR("policy for %s: %d -> %d", aPath, perms, perms | aPerms);
}
perms |= aPerms;
mMap.InsertOrUpdate(path, perms);
}
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,
const nsACString& aPath) {
int origPerms;
if (!mMap.Get(aPath, &origPerms)) {
origPerms = MAY_ACCESS;
} else {
MOZ_ASSERT(origPerms & MAY_ACCESS);
}
int newPerms = origPerms | aPerms | RECURSIVE;
auto& perms = mMap.LookupOrInsert(aPath, MAY_ACCESS);
MOZ_ASSERT(perms & MAY_ACCESS);
int newPerms = perms | aPerms | RECURSIVE;
if (SandboxInfo::Get().Test(SandboxInfo::kVerbose)) {
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,