Bug 1351663 - Ensure that OriginAttributes is initialized when nsCookieService::Add receives a SameSite parameter draft
authorRob Wu <rob@robwu.nl>
Sat, 09 Jun 2018 01:21:02 +0200
changeset 813065 32e8a023568ab9932319345cd4ddba8711fe036a
parent 813064 6db2e8184c1f49f000a2a743853c9a4a1c319662
child 813066 fbb47c48fd9962d0e1a566813ea911b51da1ae78
push id114753
push userbmo:rob@robwu.nl
push dateMon, 02 Jul 2018 10:34:57 +0000
bugs1351663
milestone63.0a1
Bug 1351663 - Ensure that OriginAttributes is initialized when nsCookieService::Add receives a SameSite parameter InitializeOriginAttributes takes aArgc and only initializes the parameter when aArgc is 1. nsCookieService::Add takes another optional parameter, namely aSameSite. If a caller sets this SameSite flag, then InitializeOriginAttributes would skip the initialization of the OriginAttributes. This was caught by a private browsing test in toolkit/components/extensions/test/mochitest/test_ext_cookies.html (after I added support for SameSite flag in the extension API) MozReview-Commit-ID: HLfte7x1X7T
netwerk/cookie/nsCookieService.cpp
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -2554,23 +2554,23 @@ nsCookieService::Add(const nsACString &a
                      bool              aIsHttpOnly,
                      bool              aIsSession,
                      int64_t           aExpiry,
                      JS::HandleValue   aOriginAttributes,
                      int32_t           aSameSite,
                      JSContext*        aCx,
                      uint8_t           aArgc)
 {
-  MOZ_ASSERT(aArgc == 0 || aArgc == 1);
+  MOZ_ASSERT(aArgc == 0 || aArgc == 1 || aArgc == 2);
 
   OriginAttributes attrs;
   nsresult rv = InitializeOriginAttributes(&attrs,
                                            aOriginAttributes,
                                            aCx,
-                                           aArgc,
+                                           aArgc == 0 ? 0 : 1,
                                            u"nsICookieManager.add()",
                                            u"2");
   NS_ENSURE_SUCCESS(rv, rv);
 
   return AddNative(aHost, aPath, aName, aValue, aIsSecure, aIsHttpOnly,
                    aIsSession, aExpiry, &attrs, aSameSite);
 }