Disallow embeddings reaching into our guts (part 1: jsnum.h, bug 548205, r=brendan).

This commit is contained in:
Andreas Gal 2010-03-01 13:30:23 -08:00
parent 8167bb1a7c
commit 4b7c35b234
7 changed files with 35 additions and 19 deletions

View File

@ -42,8 +42,12 @@
#ifndef nsContentUtils_h___
#define nsContentUtils_h___
#include <math.h>
#if defined(XP_WIN) || defined(XP_OS2)
#include <float.h>
#endif
#include "jsprvtd.h"
#include "jsnum.h"
#include "nsAString.h"
#include "nsIStatefulFrame.h"
#include "nsINodeInfo.h"
@ -1711,20 +1715,14 @@ private:
/*
* Check whether a floating point number is finite (not +/-infinity and not a
* NaN value). We wrap JSDOUBLE_IS_FINITE in a function because it expects to
* take the address of its argument, and because the argument must be of type
* jsdouble to have the right size and layout of bits.
*
* Note: we could try to exploit the fact that |infinity - infinity == NaN|
* instead of using JSDOUBLE_IS_FINITE. This would produce more compact code
* and perform better by avoiding type conversions and bit twiddling.
* Unfortunately, some architectures don't guarantee that |f == f| evaluates
* to true (where f is any *finite* floating point number). See
* https://bugzilla.mozilla.org/show_bug.cgi?id=369418#c63 . To play it safe
* for gecko 1.9, we just reuse JSDOUBLE_IS_FINITE.
* NaN value).
*/
inline NS_HIDDEN_(PRBool) NS_FloatIsFinite(jsdouble f) {
return JSDOUBLE_IS_FINITE(f);
#ifdef WIN32
return _finite(f);
#else
return finite(f);
#endif
}
/*

View File

@ -41,6 +41,9 @@
#define _USE_MATH_DEFINES
#endif
#include <math.h>
#if defined(XP_WIN) || defined(XP_OS2)
#include <float.h>
#endif
#include "prmem.h"
@ -87,7 +90,6 @@
#include "nsIDocShellTreeNode.h"
#include "nsIXPConnect.h"
#include "jsapi.h"
#include "jsnum.h"
#include "nsTArray.h"
@ -116,7 +118,17 @@ using namespace mozilla;
/* Float validation stuff */
#define VALIDATE(_f) if (!JSDOUBLE_IS_FINITE(_f)) return PR_FALSE
static inline bool
DoubleIsFinite(double d)
{
#ifdef WIN32
return _finite(d);
#else
return finite(d);
#endif
}
#define VALIDATE(_f) if (!DoubleIsFinite(_f)) return PR_FALSE
/* These must take doubles as args, because JSDOUBLE_IS_FINITE expects
* to take the address of its argument; we can't cast/convert in the

View File

@ -67,7 +67,6 @@
#include "jsprvtd.h" // we are using private JS typedefs...
#include "jscntxt.h"
#include "jsdbgapi.h"
#include "jsnum.h"
// General helper includes
#include "nsGlobalWindow.h"
@ -3825,7 +3824,7 @@ nsDOMClassInfo::GetArrayIndexFromId(JSContext *cx, jsval id, PRBool *aIsNumber)
jsint i = -1;
if (!JSDOUBLE_IS_INT(array_index, i)) {
if (!::JS_DoubleIsInt32(array_index, &i)) {
return -1;
}

View File

@ -40,7 +40,6 @@
#include "jsapi.h"
#include "jsdtoa.h"
#include "jsprvtd.h"
#include "jsnum.h"
#include "jsbool.h"
#include "jsarena.h"
#include "jscntxt.h"

View File

@ -193,7 +193,6 @@ INSTALLED_HEADERS = \
jslock.h \
jslong.h \
jsmath.h \
jsnum.h \
jsobj.h \
jsobjinlines.h \
json.h \

View File

@ -443,6 +443,12 @@ JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp)
return !JSVAL_IS_NULL(tvr.value());
}
JS_PUBLIC_API(JSBool)
JS_DoubleIsInt32(jsdouble d, jsint *ip)
{
return JSDOUBLE_IS_INT(d, *ip);
}
JS_PUBLIC_API(JSBool)
JS_ValueToECMAInt32(JSContext *cx, jsval v, int32 *ip)
{

View File

@ -467,6 +467,9 @@ JS_ValueToSource(JSContext *cx, jsval v);
extern JS_PUBLIC_API(JSBool)
JS_ValueToNumber(JSContext *cx, jsval v, jsdouble *dp);
extern JS_PUBLIC_API(JSBool)
JS_DoubleIsInt32(jsdouble d, jsint *ip);
/*
* Convert a value to a number, then to an int32, according to the ECMA rules
* for ToInt32.