Bug 635389 - Check for overrecursion in functions that might need it. r=jorendorff

--HG--
extra : rebase_source : 72d6f2c915a4aa19e9820ea4f66039f75421c32d
This commit is contained in:
Jeff Walden 2011-04-18 16:50:46 -04:00
parent 63ee7fd726
commit 2ff8950407
3 changed files with 53 additions and 2 deletions

View File

@ -1312,8 +1312,6 @@ static JSBool
array_toString_sub(JSContext *cx, JSObject *obj, JSBool locale,
JSString *sepstr, Value *rval)
{
JS_CHECK_RECURSION(cx, return false);
static const jschar comma = ',';
const jschar *sep;
size_t seplen;
@ -1395,6 +1393,8 @@ array_toString_sub(JSContext *cx, JSObject *obj, JSBool locale,
static JSBool
array_toString(JSContext *cx, uintN argc, Value *vp)
{
JS_CHECK_RECURSION(cx, return false);
JSObject *obj = ToObject(cx, &vp[1]);
if (!obj)
return false;
@ -1429,6 +1429,8 @@ array_toString(JSContext *cx, uintN argc, Value *vp)
static JSBool
array_toLocaleString(JSContext *cx, uintN argc, Value *vp)
{
JS_CHECK_RECURSION(cx, return false);
JSObject *obj = ToObject(cx, &vp[1]);
if (!obj)
return false;
@ -1526,6 +1528,8 @@ InitArrayObject(JSContext *cx, JSObject *obj, jsuint length, const Value *vector
static JSBool
array_join(JSContext *cx, uintN argc, Value *vp)
{
JS_CHECK_RECURSION(cx, return false);
JSString *str;
if (argc == 0 || vp[2].isUndefined()) {
str = NULL;

View File

@ -0,0 +1,46 @@
/*
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/licenses/publicdomain/
*/
//-----------------------------------------------------------------------------
var BUGNUMBER = 635389;
var summary = 'Infinite recursion via [].{toString,toLocaleString,join}';
print(BUGNUMBER + ": " + summary);
/**************
* BEGIN TEST *
**************/
try
{
var x = [];
x.join = Array.prototype.toString;
"" + x;
throw new Error("should have thrown");
}
catch (e)
{
assertEq(e instanceof InternalError, true,
"should have thrown for over-recursion");
}
try
{
var x = { toString: Array.prototype.toString, join: Array.prototype.toString };
"" + x;
throw new Error("should have thrown");
}
catch (e)
{
assertEq(e instanceof InternalError, true,
"should have thrown for over-recursion");
}
/******************************************************************************/
if (typeof reportCompare === "function")
reportCompare(true, true);
print("All tests passed!");

View File

@ -9,6 +9,7 @@ script bug352085.js
script bug472534.js
script bug496985.js
script bug566661.js
script array-toString-recursion.js
skip-if(!xulRuntime.shell) script cross-global-eval-is-indirect.js # needs newGlobal()
script eval-native-callback-is-indirect.js
script extension-methods-reject-null-undefined-this.js