From bfd03b069b21e2c3668b2fd1932484357c6f3bb1 Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Tue, 10 Mar 2015 10:32:00 +0100 Subject: [PATCH] Bug 1140714 - Pass through remote NS_OpenAnonymousTemporaryFile failure to caller. r=billm --- dom/ipc/ContentParent.cpp | 7 +++++-- dom/ipc/ContentParent.h | 2 +- dom/ipc/PContent.ipdl | 7 ++++++- xpcom/io/nsAnonymousTemporaryFile.cpp | 15 +++++++++------ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index d1b8f0daf78..c27c3fa20bf 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -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 diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 1acc1700b7a..8b19b4c0aad 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -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, diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 3b87e808358..8a290781917 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -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 element is parsed and diff --git a/xpcom/io/nsAnonymousTemporaryFile.cpp b/xpcom/io/nsAnonymousTemporaryFile.cpp index e76e1c641b4..102acad2d22 100644 --- a/xpcom/io/nsAnonymousTemporaryFile.cpp +++ b/xpcom/io/nsAnonymousTemporaryFile.cpp @@ -90,12 +90,15 @@ NS_OpenAnonymousTemporaryFile(PRFileDesc** aOutFileDesc) } if (dom::ContentChild* child = dom::ContentChild::GetSingleton()) { - ipc::FileDescriptor fd; - DebugOnly 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; }