From f24f4a4cd0da2419ad18158f75832624f4c8bb03 Mon Sep 17 00:00:00 2001 From: Pale Moon Date: Wed, 4 Oct 2017 17:40:49 +0200 Subject: [PATCH] Fix some potential rooting hazards in the NPAPI plugin interface. Found with SA. --- dom/plugins/base/nsJSNPRuntime.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/dom/plugins/base/nsJSNPRuntime.cpp b/dom/plugins/base/nsJSNPRuntime.cpp index 83ea3d5379..b4eef4860f 100644 --- a/dom/plugins/base/nsJSNPRuntime.cpp +++ b/dom/plugins/base/nsJSNPRuntime.cpp @@ -198,7 +198,8 @@ static bool NPObjWrapper_Construct(JSContext *cx, unsigned argc, JS::Value *vp); static bool -CreateNPObjectMember(NPP npp, JSContext *cx, JSObject *obj, NPObject* npobj, +CreateNPObjectMember(NPP npp, JSContext *cx, + JS::Handle obj, NPObject* npobj, JS::Handle id, NPVariant* getPropertyResult, JS::MutableHandle vp); @@ -1217,7 +1218,7 @@ nsJSObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, JS::Handle obj) // compartment for callers that plan to hold onto the result or do anything // substantial with it. static JSObject * -GetNPObjectWrapper(JSContext *cx, JSObject *aObj, bool wrapResult = true) +GetNPObjectWrapper(JSContext *cx, JS::Handle aObj, bool wrapResult = true) { JS::Rooted obj(cx, aObj); while (obj && (obj = js::CheckedUnwrap(obj))) { @@ -1237,8 +1238,9 @@ GetNPObjectWrapper(JSContext *cx, JSObject *aObj, bool wrapResult = true) } static NPObject * -GetNPObject(JSContext *cx, JSObject *obj) +GetNPObject(JSContext *cx, JS::Handle aObj) { + JS::Rooted obj(cx, aObj); obj = GetNPObjectWrapper(cx, obj, /* wrapResult = */ false); if (!obj) { return nullptr; @@ -2083,7 +2085,8 @@ LookupNPP(NPObject *npobj) } static bool -CreateNPObjectMember(NPP npp, JSContext *cx, JSObject *obj, NPObject* npobj, +CreateNPObjectMember(NPP npp, JSContext *cx, + JS::Handle aObj, NPObject* npobj, JS::Handle id, NPVariant* getPropertyResult, JS::MutableHandle vp) { @@ -2102,6 +2105,8 @@ CreateNPObjectMember(NPP npp, JSContext *cx, JSObject *obj, NPObject* npobj, // Make sure to clear all members in case something fails here // during initialization. memset(memberPrivate, 0, sizeof(NPObjectMemberPrivate)); + + JS::Rooted obj(cx, aObj); JSObject *memobj = ::JS_NewObject(cx, &sNPObjectMemberClass); if (!memobj) { @@ -2209,7 +2214,8 @@ NPObjectMember_Call(JSContext *cx, unsigned argc, JS::Value *vp) if (!memberPrivate || !memberPrivate->npobjWrapper) return false; - NPObject *npobj = GetNPObject(cx, memberPrivate->npobjWrapper); + JS::Rooted objWrapper(cx, memberPrivate->npobjWrapper); + NPObject *npobj = GetNPObject(cx, objWrapper); if (!npobj) { ThrowJSException(cx, "Call on invalid member object");