Bug 1386404 - Only do the tmp remapping if needed. r=jld

This helps with getting the tests that are running out of /tmp
to pass, who get confused if their paths change underneath them.

It's also a bit faster.

MozReview-Commit-ID: CWtngVNhA0t

--HG--
extra : rebase_source : b7fe3ad6317fafa382a2ad38c7d9d5338aeafc9b
This commit is contained in:
Gian-Carlo Pascutto 2017-10-26 18:02:10 +02:00
parent 12fb914457
commit 9dd0bca893

View File

@ -706,18 +706,22 @@ SandboxBroker::ThreadMain(void)
// Look up the first pathname but first translate relative paths. // Look up the first pathname but first translate relative paths.
pathLen = ConvertToRealPath(pathBuf, sizeof(pathBuf), pathLen); pathLen = ConvertToRealPath(pathBuf, sizeof(pathBuf), pathLen);
pathLen = RemapTempDirs(pathBuf, sizeof(pathBuf), pathLen);
perms = mPolicy->Lookup(nsDependentCString(pathBuf, pathLen)); perms = mPolicy->Lookup(nsDependentCString(pathBuf, pathLen));
// We don't have read permissions on the requested dir. // We don't have read permissions on the requested dir.
// Did we arrive from a symlink in a path that is not writable?
// Then try to figure out the original path and see if that is readable.
if (!(perms & MAY_READ)) { if (!(perms & MAY_READ)) {
// Work on the original path, // Was it a tempdir that we can remap?
// this reverses ConvertToRealPath above. pathLen = RemapTempDirs(pathBuf, sizeof(pathBuf), pathLen);
int symlinkPerms = SymlinkPermissions(recvBuf, first_len); perms = mPolicy->Lookup(nsDependentCString(pathBuf, pathLen));
if (symlinkPerms > 0) { if (!(perms & MAY_READ)) {
perms = symlinkPerms; // Did we arrive from a symlink in a path that is not writable?
// Then try to figure out the original path and see if that is
// readable. Work on the original path, this reverses
// ConvertToRealPath above.
int symlinkPerms = SymlinkPermissions(recvBuf, first_len);
if (symlinkPerms > 0) {
perms = symlinkPerms;
}
} }
} }