Bug 1102052 - Crash for PBackground protocol errors, r=mrbkap.
authorBen Turner <bent.mozilla@gmail.com>
Thu, 20 Nov 2014 11:48:18 -0800
changeset 216700 7b95b87d4085e4454ca146f4e8f3f47b8c4b1389
parent 216699 6a381fc27af802686d0a2a89119fc6402a8b39cb
child 216701 6309710dd71db42f91877e2736b5f2ed0bce23b5
push idunknown
push userunknown
push dateunknown
reviewersmrbkap
bugs1102052
milestone36.0a1
Bug 1102052 - Crash for PBackground protocol errors, r=mrbkap.
ipc/glue/BackgroundChildImpl.cpp
ipc/glue/BackgroundChildImpl.h
--- a/ipc/glue/BackgroundChildImpl.cpp
+++ b/ipc/glue/BackgroundChildImpl.cpp
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "BackgroundChildImpl.h"
 
 #include "FileDescriptorSetChild.h"
+#include "mozilla/Assertions.h"
 #include "mozilla/dom/PBlobChild.h"
 #include "mozilla/dom/indexedDB/PBackgroundIDBFactoryChild.h"
 #include "mozilla/dom/ipc/BlobChild.h"
 #include "mozilla/ipc/PBackgroundTestChild.h"
 #include "nsTraceRefcnt.h"
 
 namespace {
 
@@ -76,16 +77,49 @@ BackgroundChildImpl::BackgroundChildImpl
 
 BackgroundChildImpl::~BackgroundChildImpl()
 {
   // May happen on any thread!
   MOZ_COUNT_DTOR(mozilla::ipc::BackgroundChildImpl);
 }
 
 void
+BackgroundChildImpl::ProcessingError(Result aWhat)
+{
+  // May happen on any thread!
+
+  nsAutoCString abortMessage;
+
+  switch (aWhat) {
+
+#define HANDLE_CASE(_result)                                                   \
+    case _result:                                                              \
+      abortMessage.AssignLiteral(#_result);                                    \
+      break
+
+    HANDLE_CASE(MsgDropped);
+    HANDLE_CASE(MsgNotKnown);
+    HANDLE_CASE(MsgNotAllowed);
+    HANDLE_CASE(MsgPayloadError);
+    HANDLE_CASE(MsgProcessingError);
+    HANDLE_CASE(MsgRouteError);
+    HANDLE_CASE(MsgValueError);
+
+#undef HANDLE_CASE
+
+    default:
+      MOZ_CRASH("Unknown error code!");
+  }
+
+  // This is just MOZ_CRASH() un-inlined so that we can pass the result code as
+  // a string. MOZ_CRASH() only supports string literals at the moment.
+  MOZ_ReportCrash(abortMessage.get(), __FILE__, __LINE__); MOZ_REALLY_CRASH();
+}
+
+void
 BackgroundChildImpl::ActorDestroy(ActorDestroyReason aWhy)
 {
   // May happen on any thread!
 }
 
 PBackgroundTestChild*
 BackgroundChildImpl::AllocPBackgroundTestChild(const nsCString& aTestArg)
 {
--- a/ipc/glue/BackgroundChildImpl.h
+++ b/ipc/glue/BackgroundChildImpl.h
@@ -36,16 +36,19 @@ public:
   static ThreadLocal*
   GetThreadLocalForCurrentThread();
 
 protected:
   BackgroundChildImpl();
   virtual ~BackgroundChildImpl();
 
   virtual void
+  ProcessingError(Result aWhat) MOZ_OVERRIDE;
+
+  virtual void
   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
 
   virtual PBackgroundTestChild*
   AllocPBackgroundTestChild(const nsCString& aTestArg) MOZ_OVERRIDE;
 
   virtual bool
   DeallocPBackgroundTestChild(PBackgroundTestChild* aActor) MOZ_OVERRIDE;