Bug 1295103 - Check OriginAttributes::PopulateFromSuffix return value in nsCookieService. r=honzab draft
authorKan-Ru Chen <kanru@kanru.info>
Mon, 15 Aug 2016 18:18:19 +0800
changeset 404363 790679ea5bef333f98783c7d3aeed1729b1a9b1f
parent 404362 f1a53553352c7fb7b7659947dc0064b01cca0379
child 404364 573eea59bf2efae6109c74b230dc3dc5b825ed70
push id27198
push userbmo:kchen@mozilla.com
push dateTue, 23 Aug 2016 10:29:41 +0000
reviewershonzab
bugs1295103
milestone51.0a1
Bug 1295103 - Check OriginAttributes::PopulateFromSuffix return value in nsCookieService. r=honzab MozReview-Commit-ID: 8aN6faugiqq
netwerk/cookie/nsCookieService.cpp
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -2,16 +2,17 @@
 /* vim: set sw=2 ts=8 et tw=80 : */
 /* 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 "mozilla/Attributes.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Likely.h"
+#include "mozilla/unused.h"
 
 #include "mozilla/net/CookieServiceChild.h"
 #include "mozilla/net/NeckoCommon.h"
 
 #include "nsCookieService.h"
 #include "nsContentUtils.h"
 #include "nsIServiceManager.h"
 
@@ -486,17 +487,18 @@ public:
       if (!row)
         break;
 
       CookieDomainTuple *tuple = mDBState->hostArray.AppendElement();
       row->GetUTF8String(IDX_BASE_DOMAIN, tuple->key.mBaseDomain);
 
       nsAutoCString suffix;
       row->GetUTF8String(IDX_ORIGIN_ATTRIBUTES, suffix);
-      tuple->key.mOriginAttributes.PopulateFromSuffix(suffix);
+      DebugOnly<bool> success = tuple->key.mOriginAttributes.PopulateFromSuffix(suffix);
+      MOZ_ASSERT(success);
 
       tuple->cookie =
         gCookieService->GetCookieFromRow(row, tuple->key.mOriginAttributes);
     }
 
     return NS_OK;
   }
   NS_IMETHOD HandleCompletion(uint16_t aReason) override
@@ -859,17 +861,18 @@ SetAppIdFromOriginAttributesSQLFunction:
   mozIStorageValueArray* aFunctionArguments, nsIVariant** aResult)
 {
   nsresult rv;
   nsAutoCString suffix;
   NeckoOriginAttributes attrs;
 
   rv = aFunctionArguments->GetUTF8String(0, suffix);
   NS_ENSURE_SUCCESS(rv, rv);
-  attrs.PopulateFromSuffix(suffix);
+  bool success = attrs.PopulateFromSuffix(suffix);
+  NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
 
   RefPtr<nsVariant> outVar(new nsVariant());
   rv = outVar->SetAsInt32(attrs.mAppId);
   NS_ENSURE_SUCCESS(rv, rv);
 
   outVar.forget(aResult);
   return NS_OK;
 }
@@ -891,17 +894,18 @@ SetInBrowserFromOriginAttributesSQLFunct
   mozIStorageValueArray* aFunctionArguments, nsIVariant** aResult)
 {
   nsresult rv;
   nsAutoCString suffix;
   NeckoOriginAttributes attrs;
 
   rv = aFunctionArguments->GetUTF8String(0, suffix);
   NS_ENSURE_SUCCESS(rv, rv);
-  attrs.PopulateFromSuffix(suffix);
+  bool success = attrs.PopulateFromSuffix(suffix);
+  NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
 
   RefPtr<nsVariant> outVar(new nsVariant());
   rv = outVar->SetAsInt32(attrs.mInIsolatedMozBrowser);
   NS_ENSURE_SUCCESS(rv, rv);
 
   outVar.forget(aResult);
   return NS_OK;
 }
@@ -2793,17 +2797,19 @@ nsCookieService::EnsureReadComplete()
       break;
 
     // Make sure we haven't already read the data.
     stmt->GetUTF8String(IDX_BASE_DOMAIN, baseDomain);
 
     nsAutoCString suffix;
     NeckoOriginAttributes attrs;
     stmt->GetUTF8String(IDX_ORIGIN_ATTRIBUTES, suffix);
-    attrs.PopulateFromSuffix(suffix);
+    // If PopulateFromSuffix failed we just ignore the OA attributes
+    // that we don't support
+    Unused << attrs.PopulateFromSuffix(suffix);
 
     nsCookieKey key(baseDomain, attrs);
     if (mDefaultDBState->readSet.GetEntry(key))
       continue;
 
     CookieDomainTuple* tuple = array.AppendElement();
     tuple->key = key;
     tuple->cookie = GetCookieFromRow(stmt, attrs);