Bug 1140714 - Pass through remote NS_OpenAnonymousTemporaryFile failure to caller. r=billm

This commit is contained in:
Jed Davis 2015-03-10 10:32:00 +01:00
parent ebca8598ef
commit bfd03b069b
4 changed files with 21 additions and 10 deletions

View File

@ -4459,12 +4459,15 @@ ContentParent::RecvBackUpXResources(const FileDescriptor& aXSocketFd)
}
bool
ContentParent::RecvOpenAnonymousTemporaryFile(FileDescriptor *aFD)
ContentParent::RecvOpenAnonymousTemporaryFile(FileDescOrError *aFD)
{
PRFileDesc *prfd;
nsresult rv = NS_OpenAnonymousTemporaryFile(&prfd);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
// Returning false will kill the child process; instead
// propagate the error and let the child handle it.
*aFD = rv;
return true;
}
*aFD = FileDescriptor(FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(prfd)));
// The FileDescriptor object owns a duplicate of the file handle; we

View File

@ -762,7 +762,7 @@ private:
RecvBackUpXResources(const FileDescriptor& aXSocketFd) MOZ_OVERRIDE;
virtual bool
RecvOpenAnonymousTemporaryFile(FileDescriptor* aFD) MOZ_OVERRIDE;
RecvOpenAnonymousTemporaryFile(FileDescOrError* aFD) MOZ_OVERRIDE;
virtual bool
RecvKeygenProcessValue(const nsString& oldValue, const nsString& challenge,

View File

@ -335,6 +335,11 @@ union MaybeFileDesc {
void_t;
};
union FileDescOrError {
FileDescriptor;
nsresult;
};
union OptionalContentId
{
ContentParentId;
@ -827,7 +832,7 @@ parent:
*/
BackUpXResources(FileDescriptor aXSocketFd);
sync OpenAnonymousTemporaryFile() returns (FileDescriptor aFD);
sync OpenAnonymousTemporaryFile() returns (FileDescOrError aFD);
/**
* Keygen requires us to call it after a <keygen> element is parsed and

View File

@ -90,12 +90,15 @@ NS_OpenAnonymousTemporaryFile(PRFileDesc** aOutFileDesc)
}
if (dom::ContentChild* child = dom::ContentChild::GetSingleton()) {
ipc::FileDescriptor fd;
DebugOnly<bool> succeeded = child->SendOpenAnonymousTemporaryFile(&fd);
// The child process should already have been terminated if the
// IPC had failed.
MOZ_ASSERT(succeeded);
*aOutFileDesc = PR_ImportFile(PROsfd(fd.PlatformHandle()));
dom::FileDescOrError fd;
child->SendOpenAnonymousTemporaryFile(&fd);
if (fd.type() == dom::FileDescOrError::Tnsresult) {
nsresult rv = fd.get_nsresult();
MOZ_ASSERT(NS_FAILED(rv));
return rv;
}
*aOutFileDesc =
PR_ImportFile(PROsfd(fd.get_FileDescriptor().PlatformHandle()));
return NS_OK;
}