Bug 683802 - Remove XPC_JSArgumentFormatter and friends. r=mrbkap

XPC_JSArgumentFormatter adds 3 special format string tokens to spidermonkey: %ip, %iv, and %is. These were unused outside of testing according to a free-text MXR search, and don't appear to be well-documented anywhere either. They also happen to be quite dangerous and easy to use improperly: we pass untyped variadic parameters to XPCConvert::JSData2Native with useAllocator==false. This causes JSData2Native to blindly cast the values to concrete class pointers (like nsAString*) and call methods on them.
This commit is contained in:
Bobby Holley 2011-09-23 14:50:28 -07:00
parent 0d7e07547c
commit 4170b80aaf
3 changed files with 0 additions and 109 deletions

View File

@ -58,8 +58,6 @@ XPCContext::XPCContext(XPCJSRuntime* aRuntime,
MOZ_COUNT_CTOR(XPCContext);
PR_INIT_CLIST(&mScopes);
for(const char** p = XPC_ARG_FORMATTER_FORMAT_STRINGS; *p; p++)
JS_AddArgumentFormatter(mJSContext, *p, XPC_JSArgumentFormatter);
NS_ASSERTION(!mJSContext->data2, "Must be null");
mJSContext->data2 = this;

View File

@ -1839,107 +1839,6 @@ XPCConvert::JSErrorToXPCException(XPCCallContext& ccx,
return rv;
}
/***************************************************************************/
/*
** Note: on some platforms va_list is defined as an array,
** and requires array notation.
*/
#ifdef HAVE_VA_COPY
#define VARARGS_ASSIGN(foo, bar) VA_COPY(foo,bar)
#elif defined(HAVE_VA_LIST_AS_ARRAY)
#define VARARGS_ASSIGN(foo, bar) foo[0] = bar[0]
#else
#define VARARGS_ASSIGN(foo, bar) (foo) = (bar)
#endif
// We assert below that these formats all begin with "%i".
const char* XPC_ARG_FORMATTER_FORMAT_STRINGS[] = {"%ip", "%iv", "%is", nsnull};
JSBool
XPC_JSArgumentFormatter(JSContext *cx, const char *format,
JSBool fromJS, jsval **vpp, va_list *app)
{
XPCCallContext ccx(NATIVE_CALLER, cx);
if(!ccx.IsValid())
return JS_FALSE;
jsval *vp;
va_list ap;
vp = *vpp;
VARARGS_ASSIGN(ap, *app);
nsXPTType type;
const nsIID* iid;
void* p;
NS_ASSERTION(format[0] == '%' && format[1] == 'i', "bad format!");
char which = format[2];
if(fromJS)
{
switch(which)
{
case 'p':
type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));
iid = &NS_GET_IID(nsISupports);
break;
case 'v':
type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));
iid = &NS_GET_IID(nsIVariant);
break;
case 's':
type = nsXPTType((uint8)(TD_DOMSTRING | XPT_TDP_POINTER));
iid = nsnull;
p = va_arg(ap, void *);
break;
default:
NS_ERROR("bad format!");
return JS_FALSE;
}
if(!XPCConvert::JSData2Native(ccx, &p, vp[0], type, JS_FALSE,
iid, nsnull))
return JS_FALSE;
if(which != 's')
*va_arg(ap, void **) = p;
}
else
{
switch(which)
{
case 'p':
type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));
iid = va_arg(ap, const nsIID*);
break;
case 'v':
type = nsXPTType((uint8)(TD_INTERFACE_TYPE | XPT_TDP_POINTER));
iid = &NS_GET_IID(nsIVariant);
break;
case 's':
type = nsXPTType((uint8)(TD_DOMSTRING | XPT_TDP_POINTER));
iid = nsnull;
break;
default:
NS_ERROR("bad format!");
return JS_FALSE;
}
// NOTE: MUST be retrieved *after* the iid in the 'p' case above.
p = va_arg(ap, void *);
ccx.SetScopeForNewJSObjects(JS_GetGlobalForScopeChain(cx));
if(!XPCConvert::NativeData2JS(ccx, &vp[0], &p, type, iid, nsnull))
return JS_FALSE;
}
*vpp = vp + 1;
VARARGS_ASSIGN(*app, ap);
return JS_TRUE;
}
/***************************************************************************/
// array fun...

View File

@ -223,7 +223,6 @@ void DEBUG_CheckWrapperThreadSafety(const XPCWrappedNative* wrapper);
/***************************************************************************/
// data declarations...
extern const char* XPC_ARG_FORMATTER_FORMAT_STRINGS[]; // format strings
extern const char XPC_CONTEXT_STACK_CONTRACTID[];
extern const char XPC_RUNTIME_CONTRACTID[];
extern const char XPC_EXCEPTION_CONTRACTID[];
@ -3365,11 +3364,6 @@ private:
XPCStringConvert(); // not implemented
};
extern JSBool
XPC_JSArgumentFormatter(JSContext *cx, const char *format,
JSBool fromJS, jsval **vpp, va_list *app);
/***************************************************************************/
// code for throwing exceptions into JS