diff --git a/security/sandbox/linux/broker/SandboxBroker.cpp b/security/sandbox/linux/broker/SandboxBroker.cpp index 5a44669f9e1d..5cd7d8650fe5 100644 --- a/security/sandbox/linux/broker/SandboxBroker.cpp +++ b/security/sandbox/linux/broker/SandboxBroker.cpp @@ -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,