Bug 1554289 - Add non-null checks around assignment referrerInfo to preflight HTTP channel r=valentin a=jcristau
authorThomas Nguyen <tnguyen@mozilla.com>
Fri, 31 May 2019 09:39:51 +0000
changeset 536693 4bd74b23ffb6ede616a02b8e834c09c6ae31d898
parent 536692 9bce7f0a4e570404999d4c9d630b949d1047ddfc
child 536694 11ffae4160639b957b802235977a93ffe8bdfce9
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin, jcristau
bugs1554289
milestone68.0
Bug 1554289 - Add non-null checks around assignment referrerInfo to preflight HTTP channel r=valentin a=jcristau Differential Revision: https://phabricator.services.mozilla.com/D32976
netwerk/protocol/http/nsCORSListenerProxy.cpp
--- a/netwerk/protocol/http/nsCORSListenerProxy.cpp
+++ b/netwerk/protocol/http/nsCORSListenerProxy.cpp
@@ -1530,26 +1530,28 @@ nsresult nsCORSListenerProxy::StartCORSP
   // Set up listener which will start the original channel
   RefPtr<nsCORSPreflightListener> preflightListener =
       new nsCORSPreflightListener(principal, aCallback, loadContext,
                                   withCredentials, method, preflightHeaders);
 
   rv = preflightChannel->SetNotificationCallbacks(preflightListener);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // Per https://fetch.spec.whatwg.org/#cors-preflight-fetch step 1, the
-  // request's referrer and referrer policy should match the original request.
-  nsCOMPtr<nsIReferrerInfo> referrerInfo;
-  rv = reqCh->GetReferrerInfo(getter_AddRefs(referrerInfo));
-  NS_ENSURE_SUCCESS(rv, rv);
-  if (referrerInfo) {
-    nsCOMPtr<nsIReferrerInfo> newReferrerInfo =
-        static_cast<dom::ReferrerInfo*>(referrerInfo.get())->Clone();
-    rv = preCh->SetReferrerInfo(newReferrerInfo);
+  if (preCh && reqCh) {
+    // Per https://fetch.spec.whatwg.org/#cors-preflight-fetch step 1, the
+    // request's referrer and referrer policy should match the original request.
+    nsCOMPtr<nsIReferrerInfo> referrerInfo;
+    rv = reqCh->GetReferrerInfo(getter_AddRefs(referrerInfo));
     NS_ENSURE_SUCCESS(rv, rv);
+    if (referrerInfo) {
+      nsCOMPtr<nsIReferrerInfo> newReferrerInfo =
+          static_cast<dom::ReferrerInfo*>(referrerInfo.get())->Clone();
+      rv = preCh->SetReferrerInfo(newReferrerInfo);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
   }
 
   // Start preflight
   rv = preflightChannel->AsyncOpen(preflightListener);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Return newly created preflight channel
   preflightChannel.forget(aPreflightChannel);