From 511449e134288614e3b761e43d47482fc201efd0 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Thu, 30 Jan 2025 19:20:18 +0100 Subject: [PATCH 01/13] Issue #2557 - Remove URL Constructor(DOMString url, URL base). URL Constructor(DOMString url, URL base) doesn't exist anymore in the spec. Resolves #2557 --- dom/url/URL.cpp | 60 +------------------------------------------ dom/url/URL.h | 4 --- dom/webidl/URL.webidl | 4 +-- 3 files changed, 2 insertions(+), 66 deletions(-) diff --git a/dom/url/URL.cpp b/dom/url/URL.cpp index f594c0f322..9586d46c5f 100644 --- a/dom/url/URL.cpp +++ b/dom/url/URL.cpp @@ -61,10 +61,6 @@ CreateObjectURLInternal(const GlobalObject& aGlobal, T aObject, class URLMainThread final : public URL { public: - static already_AddRefed - Constructor(const GlobalObject& aGlobal, const nsAString& aURL, - URL& aBase, ErrorResult& aRv); - static already_AddRefed Constructor(const GlobalObject& aGlobal, const nsAString& aURL, const Optional& aBase, ErrorResult& aRv); @@ -196,15 +192,6 @@ private: nsCOMPtr mURI; }; -/* static */ already_AddRefed -URLMainThread::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, - URL& aBase, ErrorResult& aRv) -{ - MOZ_ASSERT(NS_IsMainThread()); - URLMainThread& base = static_cast(aBase); - return Constructor(aGlobal.GetAsSupports(), aURL, base.GetURI(), aRv); -} - /* static */ already_AddRefed URLMainThread::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, const Optional& aBase, ErrorResult& aRv) @@ -639,10 +626,6 @@ private: class URLWorker final : public URL { public: - static already_AddRefed - Constructor(const GlobalObject& aGlobal, const nsAString& aURL, - URL& aBase, ErrorResult& aRv); - static already_AddRefed Constructor(const GlobalObject& aGlobal, const nsAString& aURL, const Optional& aBase, ErrorResult& aRv); @@ -934,7 +917,6 @@ private: const nsString mURL; nsString mBase; // IsVoid() if we have no base URI string. - RefPtr mBaseProxy; RefPtr mRetval; @@ -953,17 +935,6 @@ public: mWorkerPrivate->AssertIsOnWorkerThread(); } - ConstructorRunnable(WorkerPrivate* aWorkerPrivate, - const nsAString& aURL, URLProxy* aBaseProxy) - : WorkerMainThreadRunnable(aWorkerPrivate, - NS_LITERAL_CSTRING("URL :: Constructor with BaseURL")) - , mURL(aURL) - , mBaseProxy(aBaseProxy) - { - mBase.SetIsVoid(true); - mWorkerPrivate->AssertIsOnWorkerThread(); - } - bool MainThreadRun() { @@ -971,9 +942,7 @@ public: ErrorResult rv; RefPtr url; - if (mBaseProxy) { - url = URLMainThread::Constructor(nullptr, mURL, mBaseProxy->URI(), rv); - } else if (!mBase.IsVoid()) { + if (!mBase.IsVoid()) { url = URLMainThread::Constructor(nullptr, mURL, mBase, rv); } else { url = URLMainThread::Constructor(nullptr, mURL, nullptr, rv); @@ -1249,22 +1218,6 @@ FinishConstructor(JSContext* aCx, WorkerPrivate* aPrivate, return url.forget(); } -/* static */ already_AddRefed -URLWorker::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, - URL& aBase, ErrorResult& aRv) -{ - MOZ_ASSERT(!NS_IsMainThread()); - - JSContext* cx = aGlobal.Context(); - WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(cx); - - URLWorker& base = static_cast(aBase); - RefPtr runnable = - new ConstructorRunnable(workerPrivate, aURL, base.GetURLProxy()); - - return FinishConstructor(cx, workerPrivate, runnable, aRv); -} - /* static */ already_AddRefed URLWorker::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, const Optional& aBase, ErrorResult& aRv) @@ -1688,17 +1641,6 @@ URL::WrapObject(JSContext* aCx, JS::Handle aGivenProto) return URLBinding::Wrap(aCx, this, aGivenProto); } -/* static */ already_AddRefed -URL::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, - URL& aBase, ErrorResult& aRv) -{ - if (NS_IsMainThread()) { - return URLMainThread::Constructor(aGlobal, aURL, aBase, aRv); - } - - return URLWorker::Constructor(aGlobal, aURL, aBase, aRv); -} - /* static */ already_AddRefed URL::Constructor(const GlobalObject& aGlobal, const nsAString& aURL, const Optional& aBase, ErrorResult& aRv) diff --git a/dom/url/URL.h b/dom/url/URL.h index 53164b7b95..13a76d7198 100644 --- a/dom/url/URL.h +++ b/dom/url/URL.h @@ -47,10 +47,6 @@ public: virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; - static already_AddRefed - Constructor(const GlobalObject& aGlobal, const nsAString& aURL, - URL& aBase, ErrorResult& aRv); - static already_AddRefed Constructor(const GlobalObject& aGlobal, const nsAString& aURL, const Optional& aBase, ErrorResult& aRv); diff --git a/dom/webidl/URL.webidl b/dom/webidl/URL.webidl index a12635ce3f..25cf9368d4 100644 --- a/dom/webidl/URL.webidl +++ b/dom/webidl/URL.webidl @@ -12,9 +12,7 @@ * liability, trademark and document use rules apply. */ -// [Constructor(DOMString url, optional (URL or DOMString) base = "about:blank")] -[Constructor(DOMString url, URL base), - Constructor(DOMString url, optional DOMString base), +[Constructor(DOMString url, optional DOMString base), NamedConstructor=webkitURL(DOMString url, optional DOMString base), Exposed=(Window,Worker,WorkerDebugger)] interface URL { From a22bb7d1d08763b82a7998ceb3bcf768b2f7226b Mon Sep 17 00:00:00 2001 From: Moonchild Date: Sat, 1 Feb 2025 21:44:24 +0100 Subject: [PATCH 02/13] No Issue - Silence unhelpful -Qspectre warnings. --- old-configure.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/old-configure.in b/old-configure.in index cfbb84727a..b6c8dbb82e 100644 --- a/old-configure.in +++ b/old-configure.in @@ -221,6 +221,9 @@ case "$target" in # 'noexcept' used with no exception handling mode specified; # termination on exception is not guaranteed. Specify /EHsc CXXFLAGS="$CXXFLAGS -wd4577" + + # Silence unhelpful -Qspectre warnings + CXXFLAGS="$CXXFLAGS -wd5045" if test -n "$WIN_UCRT_REDIST_DIR"; then if test ! -d "$WIN_UCRT_REDIST_DIR"; then From d377b3ae17a0fdba45e012a914915af6d3adde02 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 4 Feb 2025 15:52:23 +0100 Subject: [PATCH 03/13] Bump default Firefox compatversion to 115.0 --- modules/libpref/init/all.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 9bbb026997..6adcb30ee2 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -25,7 +25,7 @@ pref("general.useragent.locale", "chrome://global/locale/intl.properties"); // Platform User-agent compatibility mode default settings pref("general.useragent.compatMode.gecko", false); pref("general.useragent.compatMode.firefox", false); -pref("general.useragent.compatMode.version", "102.0"); +pref("general.useragent.compatMode.version", "115.0"); pref("general.useragent.appVersionIsBuildID", false); // In order to disable all overrides by default, don't initialize From 9d8a3f0848053df373c61071e9cd0da6a1ad36a5 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 4 Feb 2025 18:01:17 +0100 Subject: [PATCH 04/13] [DOM] Reset mCompileResult in txMozillaXSLTProcessor::ImportStylesheet. --- dom/xslt/xslt/txMozillaXSLTProcessor.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp index 0df80716c1..867bc53392 100644 --- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp +++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp @@ -604,6 +604,9 @@ txMozillaXSLTProcessor::ImportStylesheet(nsIDOMNode *aStyle) NS_ENSURE_TRUE(!mStylesheetDocument && !mStylesheet, NS_ERROR_NOT_IMPLEMENTED); + // Reset mCompileResult when importing. + mCompileResult = NS_OK; + nsCOMPtr node = do_QueryInterface(aStyle); if (!node || !nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->Subsumes(node->NodePrincipal())) { return NS_ERROR_DOM_SECURITY_ERR; From ecb18ddf57705c494f516dd3c2578ee9a76efe77 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 4 Feb 2025 18:09:28 +0100 Subject: [PATCH 05/13] [NSS] Simplify error handling in get_token_objects_for_cache. --- security/nss/lib/dev/devutil.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/security/nss/lib/dev/devutil.c b/security/nss/lib/dev/devutil.c index 74c32f088f..8b84b39445 100644 --- a/security/nss/lib/dev/devutil.c +++ b/security/nss/lib/dev/devutil.c @@ -584,8 +584,11 @@ get_token_objects_for_cache( } else { PRUint32 j; for (j = 0; j < i; j++) { - /* sigh */ - nssToken_AddRef(cache->objects[objectType][j]->object->token); + /* Objects that were successfully added to the cache do not own a + * token reference (they share a reference with the cache itself). + * Nulling out the pointer here prevents the token's refcount + * from being decremented in nssCryptokiObject_Destroy */ + cache->objects[objectType][j]->object->token = NULL; nssArena_Destroy(cache->objects[objectType][j]->arena); } nss_ZFreeIf(cache->objects[objectType]); From dcb76fe0f7bbb2701b916aa3bd4edba11c14f03e Mon Sep 17 00:00:00 2001 From: Moonchild Date: Tue, 4 Feb 2025 18:12:01 +0100 Subject: [PATCH 06/13] [NSS] Ensure zero-initialization of collectArgs.cert --- security/nss/lib/pkcs7/certread.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/security/nss/lib/pkcs7/certread.c b/security/nss/lib/pkcs7/certread.c index 15094f2d78..1d44e0e38e 100644 --- a/security/nss/lib/pkcs7/certread.c +++ b/security/nss/lib/pkcs7/certread.c @@ -520,6 +520,8 @@ CERT_DecodeCertFromPackage(char *certbuf, int certlen) CERTCertificate *cert = NULL; collectArgs.arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); + collectArgs.cert.data = NULL; + collectArgs.cert.len = 0; rv = CERT_DecodeCertPackage(certbuf, certlen, collect_certs, (void *)&collectArgs); From 7163430d1ad41e02e1aab2de00488ba27588d7d7 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 5 Feb 2025 15:29:23 +0100 Subject: [PATCH 07/13] Null-check inputs for String and BigInt Crash fix for null crash when feeding bogus strings or BigInts to StructuredClone. --- js/src/vm/StructuredClone.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/src/vm/StructuredClone.cpp b/js/src/vm/StructuredClone.cpp index 93f4fae626..25e9e93b3b 100644 --- a/js/src/vm/StructuredClone.cpp +++ b/js/src/vm/StructuredClone.cpp @@ -1059,6 +1059,11 @@ JSStructuredCloneWriter::reportDataCloneError(uint32_t errorId) bool JSStructuredCloneWriter::writeString(uint32_t tag, JSString* str) { + // Nullcheck input + if (!str) { + return false; + } + JSLinearString* linear = str->ensureLinear(context()); if (!linear) return false; @@ -1079,6 +1084,11 @@ JSStructuredCloneWriter::writeString(uint32_t tag, JSString* str) bool JSStructuredCloneWriter::writeBigInt(uint32_t tag, BigInt* bi) { + // Nullcheck input + if (!bi) { + return false; + } + bool signBit = bi->isNegative(); size_t length = bi->digitLength(); // The length must fit in 31 bits to leave room for a sign bit. From 4da1b56b6aa3ddf4fa63967f16a03010e7e3676a Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 5 Feb 2025 19:55:49 +0100 Subject: [PATCH 08/13] Issue #2690 - Add AES-KW purposed keys to list of allowable keys to unwrap. --- dom/crypto/WebCryptoTask.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index 34a4c877d7..e004ab6fc8 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -3574,6 +3574,7 @@ WebCryptoTask::CreateUnwrapKeyTask(nsIGlobalObject* aGlobal, if (keyAlgName.EqualsASCII(WEBCRYPTO_ALG_AES_CBC) || keyAlgName.EqualsASCII(WEBCRYPTO_ALG_AES_CTR) || keyAlgName.EqualsASCII(WEBCRYPTO_ALG_AES_GCM) || + keyAlgName.EqualsASCII(WEBCRYPTO_ALG_AES_KW) || keyAlgName.EqualsASCII(WEBCRYPTO_ALG_HKDF) || keyAlgName.EqualsASCII(WEBCRYPTO_ALG_HMAC)) { importTask = new ImportSymmetricKeyTask(aGlobal, aCx, aFormat, From 7039b5a95d14c2a2343a26f5b4cc794996fb6996 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 5 Feb 2025 19:56:46 +0100 Subject: [PATCH 09/13] Issue #2690 - Replace SyntaxError with TypeError for derive_bits_keys. --- dom/crypto/WebCryptoTask.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index e004ab6fc8..cbb95f966b 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -170,7 +170,7 @@ Coerce(JSContext* aCx, T& aTarget, const OOS& aAlgorithm) JS::RootedValue value(aCx, JS::ObjectValue(*aAlgorithm.GetAsObject())); if (!aTarget.Init(aCx, value)) { - return NS_ERROR_DOM_SYNTAX_ERR; + return NS_ERROR_DOM_TYPE_MISMATCH_ERR; } return NS_OK; @@ -401,9 +401,14 @@ WebCryptoTask::FailWithError(nsresult aRv) { MOZ_ASSERT(IsOnOriginalThread()); - // Blindly convert nsresult to DOMException - // Individual tasks must ensure they pass the right values - mResultPromise->MaybeReject(aRv); + if (aRv == NS_ERROR_DOM_TYPE_MISMATCH_ERR) { + mResultPromise->MaybeRejectWithTypeError( + "The operation could not be performed."); + } else { + // Blindly convert nsresult to DOMException + // Individual tasks must ensure they pass the right values + mResultPromise->MaybeReject(aRv); + } // Manually release mResultPromise while we're on the main thread mResultPromise = nullptr; mWorkerHolder = nullptr; @@ -2927,7 +2932,7 @@ public: RootedDictionary params(aCx); mEarlyRv = Coerce(aCx, params, aAlgorithm); if (NS_FAILED(mEarlyRv)) { - mEarlyRv = NS_ERROR_DOM_SYNTAX_ERR; + /* The returned code is installed by Coerce function. */ return; } From 263bf279a72913209283848eff73e59014a93886 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 5 Feb 2025 22:14:02 +0100 Subject: [PATCH 10/13] Issue #2690 - Throw a NotSupportedError in case of unknown algorithm name. Syntax error is incorrect for this case. --- dom/crypto/WebCryptoTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index cbb95f966b..b8239b9046 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -152,7 +152,7 @@ GetAlgorithmName(JSContext* aCx, const OOS& aAlgorithm, nsString& aName) } if (!NormalizeToken(aName, aName)) { - return NS_ERROR_DOM_SYNTAX_ERR; + return NS_ERROR_DOM_NOT_SUPPORTED_ERR; } return NS_OK; From 3d7a95ab4426eab9071613f31a254f3f027d399f Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 5 Feb 2025 22:51:26 +0100 Subject: [PATCH 11/13] Issue #2690 - Convert error from non-existing convenience function. Didn't check that the convenience function existed for this. Throw the error manually, instead. TO-DO: Add these convenience functions for one-shot errors. --- dom/bindings/Errors.msg | 1 + dom/crypto/WebCryptoTask.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dom/bindings/Errors.msg b/dom/bindings/Errors.msg index d22ef2c27f..db689e5bc0 100644 --- a/dom/bindings/Errors.msg +++ b/dom/bindings/Errors.msg @@ -43,6 +43,7 @@ MSG_DEF(MSG_GLOBAL_NOT_NATIVE, 0, JSEXN_TYPEERR, "Global is not a native object. MSG_DEF(MSG_ENCODING_NOT_SUPPORTED, 1, JSEXN_RANGEERR, "The given encoding '{0}' is not supported.") MSG_DEF(MSG_DOM_ENCODING_NOT_UTF, 0, JSEXN_RANGEERR, "The encoding must be utf-8, utf-16, or utf-16be.") MSG_DEF(MSG_DOM_DECODING_FAILED, 0, JSEXN_TYPEERR, "Decoding failed.") +MSG_DEF(MSG_DOM_OPERATION_FAILED, 0, JSEXN_TYPEERR, "The operation could not be performed.") MSG_DEF(MSG_NOT_FINITE, 1, JSEXN_TYPEERR, "{0} is not a finite floating-point value.") MSG_DEF(MSG_INVALID_VERSION, 0, JSEXN_TYPEERR, "0 (Zero) is not a valid database version.") MSG_DEF(MSG_INVALID_BYTESTRING, 2, JSEXN_TYPEERR, "Cannot convert string to ByteString because the character" diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index b8239b9046..644afaf6f3 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -402,8 +402,9 @@ WebCryptoTask::FailWithError(nsresult aRv) MOZ_ASSERT(IsOnOriginalThread()); if (aRv == NS_ERROR_DOM_TYPE_MISMATCH_ERR) { - mResultPromise->MaybeRejectWithTypeError( - "The operation could not be performed."); + ErrorResult rv; + rv.ThrowTypeError(); + mResultPromise->MaybeReject(rv); } else { // Blindly convert nsresult to DOMException // Individual tasks must ensure they pass the right values From e1e7a0c5bc94e3fc4523e37c67d8a907ceb6ddbe Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 5 Feb 2025 22:53:05 +0100 Subject: [PATCH 12/13] Issue #2690 - Allow 0-length keys/empty passwords for PBKDF2. --- dom/crypto/WebCryptoTask.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index 644afaf6f3..eab16fd1d2 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -1544,7 +1544,8 @@ public: } // Check that we have valid key data. - if (mKeyData.Length() == 0) { + // Zero-length key is allowed for PBKDF2 since it will be padded. + if (mKeyData.Length() == 0 && !mAlgName.EqualsLiteral(WEBCRYPTO_ALG_PBKDF2)) { return NS_ERROR_DOM_DATA_ERR; } @@ -2741,12 +2742,6 @@ public: { CHECK_KEY_ALGORITHM(aKey.Algorithm(), WEBCRYPTO_ALG_PBKDF2); - // Check that we got a symmetric key - if (mSymKey.Length() == 0) { - mEarlyRv = NS_ERROR_DOM_INVALID_ACCESS_ERR; - return; - } - RootedDictionary params(aCx); mEarlyRv = Coerce(aCx, params, aAlgorithm); if (NS_FAILED(mEarlyRv)) { @@ -2754,9 +2749,9 @@ public: return; } - // length must be a multiple of 8 bigger than zero. + // Length must be a multiple of 8 bigger than zero. if (aLength == 0 || aLength % 8) { - mEarlyRv = NS_ERROR_DOM_DATA_ERR; + mEarlyRv = NS_ERROR_DOM_OPERATION_ERR; return; } From 514122789605b6f2bc0c230a2183d5718df717c0 Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 5 Feb 2025 22:53:46 +0100 Subject: [PATCH 13/13] Issue #2690 - Remove additional incorrect syntax error result values. --- dom/crypto/WebCryptoTask.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/dom/crypto/WebCryptoTask.cpp b/dom/crypto/WebCryptoTask.cpp index eab16fd1d2..892c2f3a03 100644 --- a/dom/crypto/WebCryptoTask.cpp +++ b/dom/crypto/WebCryptoTask.cpp @@ -2214,7 +2214,6 @@ public: nsString algName; mEarlyRv = GetAlgorithmName(aCx, aAlgorithm, algName); if (NS_FAILED(mEarlyRv)) { - mEarlyRv = NS_ERROR_DOM_SYNTAX_ERR; return; } @@ -2243,7 +2242,6 @@ public: nsString hashName; mEarlyRv = GetAlgorithmName(aCx, params.mHash, hashName); if (NS_FAILED(mEarlyRv)) { - mEarlyRv = NS_ERROR_DOM_SYNTAX_ERR; return; } @@ -2341,7 +2339,6 @@ GenerateAsymmetricKeyTask::GenerateAsymmetricKeyTask( // Extract algorithm name mEarlyRv = GetAlgorithmName(aCx, aAlgorithm, mAlgName); if (NS_FAILED(mEarlyRv)) { - mEarlyRv = NS_ERROR_DOM_SYNTAX_ERR; return; } @@ -2364,7 +2361,6 @@ GenerateAsymmetricKeyTask::GenerateAsymmetricKeyTask( nsString hashName; mEarlyRv = GetAlgorithmName(aCx, params.mHash, hashName); if (NS_FAILED(mEarlyRv)) { - mEarlyRv = NS_ERROR_DOM_SYNTAX_ERR; return; }