Bug 1459666 - Ensure that DivertToParent is only called during OnStartRequest r=dragana
☠☠ backed out by 104f1728e3bc ☠ ☠
authorValentin Gosu <valentin.gosu@gmail.com>
Mon, 21 May 2018 21:16:10 +0200
changeset 419889 6cb4b8d4daad7ecd3335352c505ab2262ca2141e
parent 419888 4267d07cfc2175b7127724c38952de74c0d88ce2
child 419890 898c5c1920bd221336841f74857fce2fe9c3e8cb
push id34052
push userccoroiu@mozilla.com
push dateFri, 25 May 2018 17:52:14 +0000
treeherdermozilla-central@94d7f0e1c4d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana
bugs1459666
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1459666 - Ensure that DivertToParent is only called during OnStartRequest r=dragana
netwerk/protocol/ftp/FTPChannelChild.cpp
netwerk/protocol/ftp/FTPChannelChild.h
--- a/netwerk/protocol/ftp/FTPChannelChild.cpp
+++ b/netwerk/protocol/ftp/FTPChannelChild.cpp
@@ -307,16 +307,21 @@ FTPChannelChild::RecvOnStartRequest(cons
 void
 FTPChannelChild::DoOnStartRequest(const nsresult& aChannelStatus,
                                   const int64_t& aContentLength,
                                   const nsCString& aContentType,
                                   const PRTime& aLastModified,
                                   const nsCString& aEntityID,
                                   const URIParams& aURI)
 {
+  mDuringOnStart = true;
+  auto clearDuringFlag = mozilla::MakeScopeExit([this] {
+    this->mDuringOnStart = false;
+  });
+
   LOG(("FTPChannelChild::DoOnStartRequest [this=%p]\n", this));
 
   // mFlushedForDiversion and mDivertingToParent should NEVER be set at this
   // stage, as they are set in the listener's OnStartRequest.
   MOZ_RELEASE_ASSERT(!mFlushedForDiversion,
     "mFlushedForDiversion should be unset before OnStartRequest!");
   MOZ_RELEASE_ASSERT(!mDivertingToParent,
     "mDivertingToParent should be unset before OnStartRequest!");
@@ -887,16 +892,21 @@ FTPChannelChild::DivertToParent(ChannelD
   MOZ_RELEASE_ASSERT(aChild);
   MOZ_RELEASE_ASSERT(gNeckoChild);
   MOZ_RELEASE_ASSERT(!mDivertingToParent);
   NS_ENSURE_TRUE(!static_cast<ContentChild*>(gNeckoChild->Manager())->
                    IsShuttingDown(), NS_ERROR_FAILURE);
 
   LOG(("FTPChannelChild::DivertToParent [this=%p]\n", this));
 
+  // This method should only be called during OnStartRequest.
+  if (!mDuringOnStart) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+
   // We must fail DivertToParent() if there's no parent end of the channel (and
   // won't be!) due to early failure.
   if (NS_FAILED(mStatus) && !mIPCOpen) {
     return mStatus;
   }
 
   nsresult rv = Suspend();
   if (NS_WARN_IF(NS_FAILED(rv))) {
--- a/netwerk/protocol/ftp/FTPChannelChild.h
+++ b/netwerk/protocol/ftp/FTPChannelChild.h
@@ -141,16 +141,20 @@ private:
   // OnStartRequest is finally called
   nsTArray<UniquePtr<ChannelEvent>> mUnknownDecoderEventQ;
   bool mUnknownDecoderInvolved;
 
   bool mCanceled;
   uint32_t mSuspendCount;
   bool mIsPending;
 
+  // This will only be true while DoOnStartRequest is in progress.
+  // It is used to enforce that DivertToParent is only called during that time.
+  bool mDuringOnStart = false;
+
   PRTime mLastModifiedTime;
   uint64_t mStartPos;
   nsCString mEntityID;
 
   // Once set, OnData and possibly OnStop will be diverted to the parent.
   bool mDivertingToParent;
   // Once set, no OnStart/OnData/OnStop callbacks should be received from the
   // parent channel, nor dequeued from the ChannelEventQueue.