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
--- 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);
}