From 8398fd4d3294a98be2dcac24d467be0eafaa46af Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 11 Sep 2026 14:31:41 +0000 Subject: [PATCH] Bug 2067107 - Check string allocation in ModuleLoader::CreateTextModule. r=dom-core-reviewers,jjaschke Differential Revision: https://phabricator.services.mozilla.com/D325000 --- dom/script/ModuleLoader.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dom/script/ModuleLoader.cpp b/dom/script/ModuleLoader.cpp index 6e964d23c0df..77b5c6f5ff96 100644 --- a/dom/script/ModuleLoader.cpp +++ b/dom/script/ModuleLoader.cpp @@ -592,7 +592,7 @@ nsresult ModuleLoader::CreateTextModule( aRequest->mLoadContext.get()); NS_ENSURE_SUCCESS(rv, rv); - auto compile = [&](auto& source) { + auto compile = [&](auto& source) -> JSObject* { using T = decltype(source); static_assert(std::is_same_v&> || std::is_same_v&>); @@ -604,6 +604,9 @@ nsresult ModuleLoader::CreateTextModule( } else { str = JS_NewUCStringCopyN(aCx, source.get(), source.length()); } + if (!str) { + return nullptr; + } JS::Rooted defaultExport(aCx, JS::StringValue(str)); return JS::CreateDefaultExportSyntheticModule(aCx, defaultExport);