Bug 1320199 - Add a function for throwing permission denied errors. r=arai

This commit is contained in:
Tom Schuster 2016-11-30 16:06:06 +01:00
Родитель cd70af2e05
Коммит 3653728178
12 изменённых файлов: 40 добавлений и 38 удалений

Просмотреть файл

@ -2242,7 +2242,7 @@ js::Promise_then(JSContext* cx, unsigned argc, Value* vp)
} else { } else {
RootedObject unwrappedPromiseObj(cx, CheckedUnwrap(promiseObj)); RootedObject unwrappedPromiseObj(cx, CheckedUnwrap(promiseObj));
if (!unwrappedPromiseObj) { if (!unwrappedPromiseObj) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_UNWRAP_DENIED); ReportAccessDenied(cx);
return false; return false;
} }
if (!unwrappedPromiseObj->is<PromiseObject>()) { if (!unwrappedPromiseObj->is<PromiseObject>()) {

Просмотреть файл

@ -2582,7 +2582,7 @@ SharedAddress(JSContext* cx, unsigned argc, Value* vp)
#else #else
RootedObject obj(cx, CheckedUnwrap(&args[0].toObject())); RootedObject obj(cx, CheckedUnwrap(&args[0].toObject()));
if (!obj) { if (!obj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
if (!obj->is<SharedArrayBufferObject>()) { if (!obj->is<SharedArrayBufferObject>()) {
@ -3579,12 +3579,12 @@ GetLcovInfo(JSContext* cx, unsigned argc, Value* vp)
if (args.hasDefined(0)) { if (args.hasDefined(0)) {
global = ToObject(cx, args[0]); global = ToObject(cx, args[0]);
if (!global) { if (!global) {
JS_ReportErrorASCII(cx, "First argument should be an object"); JS_ReportErrorASCII(cx, "Permission denied to access global");
return false; return false;
} }
global = CheckedUnwrap(global); global = CheckedUnwrap(global);
if (!global) { if (!global) {
JS_ReportErrorASCII(cx, "Permission denied to access global"); ReportAccessDenied(cx);
return false; return false;
} }
if (!global->is<GlobalObject>()) { if (!global->is<GlobalObject>()) {

Просмотреть файл

@ -155,7 +155,8 @@ MSG_DEF(JSMSG_CSP_BLOCKED_FUNCTION, 0, JSEXN_ERR, "call to Function() blocked
// Wrappers // Wrappers
MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 1, JSEXN_ERR, "Permission denied to define accessor property {0}") MSG_DEF(JSMSG_ACCESSOR_DEF_DENIED, 1, JSEXN_ERR, "Permission denied to define accessor property {0}")
MSG_DEF(JSMSG_DEAD_OBJECT, 0, JSEXN_TYPEERR, "can't access dead object") MSG_DEF(JSMSG_DEAD_OBJECT, 0, JSEXN_TYPEERR, "can't access dead object")
MSG_DEF(JSMSG_UNWRAP_DENIED, 0, JSEXN_ERR, "permission denied to unwrap object") MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 0, JSEXN_ERR, "Permission denied to access object")
MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 1, JSEXN_ERR, "Permission denied to access property {0}")
// JSAPI-only (Not thrown as JS exceptions) // JSAPI-only (Not thrown as JS exceptions)
MSG_DEF(JSMSG_BAD_CLONE_FUNOBJ_SCOPE, 0, JSEXN_TYPEERR, "bad cloned function scope chain") MSG_DEF(JSMSG_BAD_CLONE_FUNOBJ_SCOPE, 0, JSEXN_TYPEERR, "bad cloned function scope chain")
@ -412,8 +413,6 @@ MSG_DEF(JSMSG_CANT_SKIP_NC, 0, JSEXN_TYPEERR, "proxy can't skip a non
MSG_DEF(JSMSG_ONWKEYS_STR_SYM, 0, JSEXN_TYPEERR, "proxy [[OwnPropertyKeys]] must return an array with only string and symbol elements") MSG_DEF(JSMSG_ONWKEYS_STR_SYM, 0, JSEXN_TYPEERR, "proxy [[OwnPropertyKeys]] must return an array with only string and symbol elements")
MSG_DEF(JSMSG_MUST_REPORT_SAME_VALUE, 0, JSEXN_TYPEERR, "proxy must report the same value for a non-writable, non-configurable property") MSG_DEF(JSMSG_MUST_REPORT_SAME_VALUE, 0, JSEXN_TYPEERR, "proxy must report the same value for a non-writable, non-configurable property")
MSG_DEF(JSMSG_MUST_REPORT_UNDEFINED, 0, JSEXN_TYPEERR, "proxy must report undefined for a non-configurable accessor property without a getter") MSG_DEF(JSMSG_MUST_REPORT_UNDEFINED, 0, JSEXN_TYPEERR, "proxy must report undefined for a non-configurable accessor property without a getter")
MSG_DEF(JSMSG_OBJECT_ACCESS_DENIED, 0, JSEXN_ERR, "Permission denied to access object")
MSG_DEF(JSMSG_PROPERTY_ACCESS_DENIED, 1, JSEXN_ERR, "Permission denied to access property {0}")
MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object") MSG_DEF(JSMSG_PROXY_CONSTRUCT_OBJECT, 0, JSEXN_TYPEERR, "proxy [[Construct]] must return an object")
MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target") MSG_DEF(JSMSG_PROXY_EXTENSIBILITY, 0, JSEXN_TYPEERR, "proxy must report same extensiblitity as target")
MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined") MSG_DEF(JSMSG_PROXY_GETOWN_OBJORUNDEF, 0, JSEXN_TYPEERR, "proxy [[GetOwnProperty]] must return an object or undefined")

Просмотреть файл

@ -906,7 +906,7 @@ js::IsWrappedArrayConstructor(JSContext* cx, const Value& v, bool* result)
if (v.toObject().is<WrapperObject>()) { if (v.toObject().is<WrapperObject>()) {
JSObject* obj = CheckedUnwrap(&v.toObject()); JSObject* obj = CheckedUnwrap(&v.toObject());
if (!obj) { if (!obj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }

Просмотреть файл

@ -358,6 +358,9 @@ CheckedUnwrap(JSObject* obj, bool stopAtWindowProxy = true);
JS_FRIEND_API(JSObject*) JS_FRIEND_API(JSObject*)
UnwrapOneChecked(JSObject* obj, bool stopAtWindowProxy = true); UnwrapOneChecked(JSObject* obj, bool stopAtWindowProxy = true);
void
ReportAccessDenied(JSContext* cx);
JS_FRIEND_API(bool) JS_FRIEND_API(bool)
IsCrossCompartmentWrapper(JSObject* obj); IsCrossCompartmentWrapper(JSObject* obj);

Просмотреть файл

@ -34,7 +34,7 @@ js::AutoEnterPolicy::reportErrorIfExceptionIsNotPending(JSContext* cx, jsid id)
return; return;
if (JSID_IS_VOID(id)) { if (JSID_IS_VOID(id)) {
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_OBJECT_ACCESS_DENIED); ReportAccessDenied(cx);
} else { } else {
RootedValue idVal(cx, IdToValue(id)); RootedValue idVal(cx, IdToValue(id));
JSString* str = ValueToSource(cx, idVal); JSString* str = ValueToSource(cx, idVal);

Просмотреть файл

@ -11,18 +11,12 @@
using namespace js; using namespace js;
static void
ReportUnwrapDenied(JSContext *cx)
{
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_UNWRAP_DENIED);
}
template <class Base> template <class Base>
bool bool
SecurityWrapper<Base>::enter(JSContext* cx, HandleObject wrapper, HandleId id, SecurityWrapper<Base>::enter(JSContext* cx, HandleObject wrapper, HandleId id,
Wrapper::Action act, bool* bp) const Wrapper::Action act, bool* bp) const
{ {
ReportUnwrapDenied(cx); ReportAccessDenied(cx);
*bp = false; *bp = false;
return false; return false;
} }
@ -32,7 +26,7 @@ bool
SecurityWrapper<Base>::nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl, SecurityWrapper<Base>::nativeCall(JSContext* cx, IsAcceptableThis test, NativeImpl impl,
const CallArgs& args) const const CallArgs& args) const
{ {
ReportUnwrapDenied(cx); ReportAccessDenied(cx);
return false; return false;
} }
@ -41,7 +35,7 @@ bool
SecurityWrapper<Base>::setPrototype(JSContext* cx, HandleObject wrapper, HandleObject proto, SecurityWrapper<Base>::setPrototype(JSContext* cx, HandleObject wrapper, HandleObject proto,
ObjectOpResult& result) const ObjectOpResult& result) const
{ {
ReportUnwrapDenied(cx); ReportAccessDenied(cx);
return false; return false;
} }
@ -50,7 +44,7 @@ bool
SecurityWrapper<Base>::setImmutablePrototype(JSContext* cx, HandleObject wrapper, SecurityWrapper<Base>::setImmutablePrototype(JSContext* cx, HandleObject wrapper,
bool* succeeded) const bool* succeeded) const
{ {
ReportUnwrapDenied(cx); ReportAccessDenied(cx);
return false; return false;
} }
@ -87,7 +81,7 @@ template <class Base>
bool bool
SecurityWrapper<Base>::isArray(JSContext* cx, HandleObject obj, JS::IsArrayAnswer* answer) const SecurityWrapper<Base>::isArray(JSContext* cx, HandleObject obj, JS::IsArrayAnswer* answer) const
{ {
// This should ReportUnwrapDenied(cx), but bug 849730 disagrees. :-( // This should ReportAccessDenied(cx), but bug 849730 disagrees. :-(
*answer = JS::IsArrayAnswer::NotArray; *answer = JS::IsArrayAnswer::NotArray;
return true; return true;
} }
@ -135,7 +129,7 @@ bool
SecurityWrapper<Base>::watch(JSContext* cx, HandleObject proxy, SecurityWrapper<Base>::watch(JSContext* cx, HandleObject proxy,
HandleId id, HandleObject callable) const HandleId id, HandleObject callable) const
{ {
ReportUnwrapDenied(cx); ReportAccessDenied(cx);
return false; return false;
} }
@ -144,7 +138,7 @@ bool
SecurityWrapper<Base>::unwatch(JSContext* cx, HandleObject proxy, SecurityWrapper<Base>::unwatch(JSContext* cx, HandleObject proxy,
HandleId id) const HandleId id) const
{ {
ReportUnwrapDenied(cx); ReportAccessDenied(cx);
return false; return false;
} }

Просмотреть файл

@ -382,6 +382,12 @@ js::UnwrapOneChecked(JSObject* obj, bool stopAtWindowProxy)
return handler->hasSecurityPolicy() ? nullptr : Wrapper::wrappedObject(obj); return handler->hasSecurityPolicy() ? nullptr : Wrapper::wrappedObject(obj);
} }
void
js::ReportAccessDenied(JSContext* cx)
{
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_OBJECT_ACCESS_DENIED);
}
const char Wrapper::family = 0; const char Wrapper::family = 0;
const Wrapper Wrapper::singleton((unsigned)0); const Wrapper Wrapper::singleton((unsigned)0);
const Wrapper Wrapper::singletonWithPrototype((unsigned)0, true); const Wrapper Wrapper::singletonWithPrototype((unsigned)0, true);

Просмотреть файл

@ -3575,7 +3575,7 @@ Debugger::unwrapDebuggeeArgument(JSContext* cx, const Value& v)
/* If we have a cross-compartment wrapper, dereference as far as is secure. */ /* If we have a cross-compartment wrapper, dereference as far as is secure. */
obj = CheckedUnwrap(obj); obj = CheckedUnwrap(obj);
if (!obj) { if (!obj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return nullptr; return nullptr;
} }
@ -8501,7 +8501,7 @@ DebuggerObject_checkThis(JSContext* cx, const CallArgs& args, const char* fnname
THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, fnname, args, obj); \ THIS_DEBUGOBJECT_REFERENT(cx, argc, vp, fnname, args, obj); \
obj = CheckedUnwrap(obj); \ obj = CheckedUnwrap(obj); \
if (!obj) { \ if (!obj) { \
JS_ReportErrorASCII(cx, "Permission denied to access object"); \ ReportAccessDenied(cx); \
return false; \ return false; \
} \ } \
if (!obj->is<PromiseObject>()) { \ if (!obj->is<PromiseObject>()) { \
@ -8515,7 +8515,7 @@ DebuggerObject_checkThis(JSContext* cx, const CallArgs& args, const char* fnname
THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, fnname, args, dbg, obj); \ THIS_DEBUGOBJECT_OWNER_REFERENT(cx, argc, vp, fnname, args, dbg, obj); \
obj = CheckedUnwrap(obj); \ obj = CheckedUnwrap(obj); \
if (!obj) { \ if (!obj) { \
JS_ReportErrorASCII(cx, "Permission denied to access object"); \ ReportAccessDenied(cx); \
return false; \ return false; \
} \ } \
if (!obj->is<PromiseObject>()) { \ if (!obj->is<PromiseObject>()) { \
@ -9813,7 +9813,7 @@ DebuggerObject::getErrorReport(JSContext* cx, HandleObject maybeError, JSErrorRe
obj = CheckedUnwrap(obj); obj = CheckedUnwrap(obj);
if (!obj) { if (!obj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
@ -10387,7 +10387,7 @@ DebuggerObject::requirePromise(JSContext* cx, HandleDebuggerObject object)
if (IsCrossCompartmentWrapper(referent)) { if (IsCrossCompartmentWrapper(referent)) {
referent = CheckedUnwrap(referent); referent = CheckedUnwrap(referent);
if (!referent) { if (!referent) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
} }

Просмотреть файл

@ -177,7 +177,7 @@ FindErrorInstanceOrPrototype(JSContext* cx, HandleObject obj, MutableHandleObjec
RootedObject target(cx, CheckedUnwrap(obj)); RootedObject target(cx, CheckedUnwrap(obj));
if (!target) { if (!target) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
@ -196,7 +196,7 @@ FindErrorInstanceOrPrototype(JSContext* cx, HandleObject obj, MutableHandleObjec
target = CheckedUnwrap(proto); target = CheckedUnwrap(proto);
if (!target) { if (!target) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
} }

Просмотреть файл

@ -996,7 +996,7 @@ intrinsic_IsWrappedArrayBuffer(JSContext* cx, unsigned argc, Value* vp)
JSObject* unwrapped = CheckedUnwrap(obj); JSObject* unwrapped = CheckedUnwrap(obj);
if (!unwrapped) { if (!unwrapped) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
@ -1027,7 +1027,7 @@ intrinsic_PossiblyWrappedArrayBufferByteLength(JSContext* cx, unsigned argc, Val
JSObject* obj = CheckedUnwrap(&args[0].toObject()); JSObject* obj = CheckedUnwrap(&args[0].toObject());
if (!obj) { if (!obj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
@ -1052,7 +1052,7 @@ intrinsic_ArrayBufferCopyData(JSContext* cx, unsigned argc, Value* vp)
MOZ_ASSERT(wrapped->is<WrapperObject>()); MOZ_ASSERT(wrapped->is<WrapperObject>());
RootedObject toBufferObj(cx, CheckedUnwrap(wrapped)); RootedObject toBufferObj(cx, CheckedUnwrap(wrapped));
if (!toBufferObj) { if (!toBufferObj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
toBuffer = toBufferObj.as<T>(); toBuffer = toBufferObj.as<T>();
@ -1135,7 +1135,7 @@ intrinsic_IsPossiblyWrappedTypedArray(JSContext* cx, unsigned argc, Value* vp)
if (args[0].isObject()) { if (args[0].isObject()) {
JSObject* obj = CheckedUnwrap(&args[0].toObject()); JSObject* obj = CheckedUnwrap(&args[0].toObject());
if (!obj) { if (!obj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
@ -1208,7 +1208,7 @@ intrinsic_PossiblyWrappedTypedArrayLength(JSContext* cx, unsigned argc, Value* v
JSObject* obj = CheckedUnwrap(&args[0].toObject()); JSObject* obj = CheckedUnwrap(&args[0].toObject());
if (!obj) { if (!obj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }
@ -1227,7 +1227,7 @@ intrinsic_PossiblyWrappedTypedArrayHasDetachedBuffer(JSContext* cx, unsigned arg
JSObject* obj = CheckedUnwrap(&args[0].toObject()); JSObject* obj = CheckedUnwrap(&args[0].toObject());
if (!obj) { if (!obj) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }

Просмотреть файл

@ -780,7 +780,7 @@ class TypedArrayObjectTemplate : public TypedArrayObject
*/ */
JSObject* wrapped = CheckedUnwrap(bufobj); JSObject* wrapped = CheckedUnwrap(bufobj);
if (!wrapped) { if (!wrapped) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return nullptr; return nullptr;
} }
@ -1166,7 +1166,7 @@ TypedArrayObjectTemplate<T>::fromTypedArray(JSContext* cx, HandleObject other, b
} else { } else {
RootedObject unwrapped(cx, CheckedUnwrap(other)); RootedObject unwrapped(cx, CheckedUnwrap(other));
if (!unwrapped) { if (!unwrapped) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return nullptr; return nullptr;
} }
@ -1825,7 +1825,7 @@ DataViewObject::constructWrapped(JSContext* cx, HandleObject bufobj, const CallA
JSObject* unwrapped = CheckedUnwrap(bufobj); JSObject* unwrapped = CheckedUnwrap(bufobj);
if (!unwrapped) { if (!unwrapped) {
JS_ReportErrorASCII(cx, "Permission denied to access object"); ReportAccessDenied(cx);
return false; return false;
} }