From c7330b5eb48cdd69b06e5f55643ea4c94303381f Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Sat, 27 Jun 2020 02:09:19 +0200 Subject: Issue #1602 - Make sure we have a JSObject before trying to get global. Dynamic script loading/unloading (thank you modules) can yank the script out from under us before the JS API for it is initialized, leading to null deref crashes. This adds a simple check if the passed-in object is sane and present. Resolves #1602 --- dom/base/ScriptSettings.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'dom/base') diff --git a/dom/base/ScriptSettings.cpp b/dom/base/ScriptSettings.cpp index d67f2167a..92ab221c9 100644 --- a/dom/base/ScriptSettings.cpp +++ b/dom/base/ScriptSettings.cpp @@ -485,7 +485,13 @@ AutoJSAPI::Init(nsIGlobalObject* aGlobalObject) bool AutoJSAPI::Init(JSObject* aObject) { - return Init(xpc::NativeGlobal(aObject)); + nsIGlobalObject* global = nullptr; + if (aObject) + global = xpc::NativeGlobal(aObject); + if (global) + return Init(global); + else + return false; } bool -- cgit v1.2.3