Bug 902375 - Strict file origin policy - handle case where the target is the parent directory of the source. r=bz

This commit is contained in:
John Schoenick 2013-08-07 14:35:20 -07:00
parent 75c88795c6
commit 1d0b574237

View File

@ -1976,19 +1976,26 @@ NS_RelaxStrictFileOriginPolicy(nsIURI *aTargetURI,
// inherit its source principal and be scriptable by that source.
//
bool sourceIsDir;
bool contained = false;
bool allowed = false;
nsresult rv = sourceFile->IsDirectory(&sourceIsDir);
if (NS_SUCCEEDED(rv) && sourceIsDir) {
rv = sourceFile->Contains(targetFile, true, &contained);
rv = sourceFile->Contains(targetFile, true, &allowed);
} else {
nsCOMPtr<nsIFile> sourceParent;
rv = sourceFile->GetParent(getter_AddRefs(sourceParent));
if (NS_SUCCEEDED(rv) && sourceParent) {
rv = sourceParent->Contains(targetFile, true, &contained);
rv = sourceParent->Equals(targetFile, &allowed);
if (NS_FAILED(rv) || !allowed) {
rv = sourceParent->Contains(targetFile, true, &allowed);
} else {
MOZ_ASSERT(aAllowDirectoryTarget,
"sourceFile->Parent == targetFile, but targetFile "
"should've been disallowed if it is a directory");
}
}
}
if (NS_SUCCEEDED(rv) && contained) {
if (NS_SUCCEEDED(rv) && allowed) {
return true;
}