Bug 1034627 part 3 - Fix SandboxDump, AccessCheck.cpp to work with Latin1 strings and nursery strings. r=bholley

This commit is contained in:
Jan de Mooij 2014-07-10 17:36:35 +02:00
Родитель edbd6779df
Коммит b986e6ec0f
2 изменённых файлов: 13 добавлений и 18 удалений

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

@ -98,13 +98,8 @@ SandboxDump(JSContext *cx, unsigned argc, jsval *vp)
if (!str) if (!str)
return false; return false;
size_t length; JSAutoByteString utf8str;
const jschar *chars = JS_GetStringCharsZAndLength(cx, str, &length); char *cstr = utf8str.encodeUtf8(cx, str);
if (!chars)
return false;
nsDependentString wstr(chars, length);
char *cstr = ToNewUTF8String(wstr);
if (!cstr) if (!cstr)
return false; return false;
@ -123,7 +118,6 @@ SandboxDump(JSContext *cx, unsigned argc, jsval *vp)
fputs(cstr, stdout); fputs(cstr, stdout);
fflush(stdout); fflush(stdout);
NS_Free(cstr);
args.rval().setBoolean(true); args.rval().setBoolean(true);
return true; return true;
} }

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

@ -91,7 +91,7 @@ AccessCheck::getPrincipal(JSCompartment *compartment)
} }
#define NAME(ch, str, cases) \ #define NAME(ch, str, cases) \
case ch: if (!strcmp(name, str)) switch (propChars[0]) { cases }; break; case ch: if (!strcmp(name, str)) switch (propChar0) { cases }; break;
#define PROP(ch, actions) case ch: { actions }; break; #define PROP(ch, actions) case ch: { actions }; break;
#define RW(str) if (JS_FlatStringEqualsAscii(prop, str)) return true; #define RW(str) if (JS_FlatStringEqualsAscii(prop, str)) return true;
#define R(str) if (!set && JS_FlatStringEqualsAscii(prop, str)) return true; #define R(str) if (!set && JS_FlatStringEqualsAscii(prop, str)) return true;
@ -103,18 +103,18 @@ AccessCheck::getPrincipal(JSCompartment *compartment)
static bool static bool
IsPermitted(const char *name, JSFlatString *prop, bool set) IsPermitted(const char *name, JSFlatString *prop, bool set)
{ {
size_t propLength; size_t propLength = JS_GetStringLength(JS_FORGET_STRING_FLATNESS(prop));
const jschar *propChars =
JS_GetInternedStringCharsAndLength(JS_FORGET_STRING_FLATNESS(prop), &propLength);
if (!propLength) if (!propLength)
return false; return false;
jschar propChar0 = JS_GetFlatStringCharAt(prop, 0);
switch (name[0]) { switch (name[0]) {
NAME('L', "Location", NAME('L', "Location",
PROP('h', W("href")) PROP('h', W("href"))
PROP('r', R("replace"))) PROP('r', R("replace")))
case 'W': case 'W':
if (!strcmp(name, "Window")) if (!strcmp(name, "Window"))
return dom::WindowBinding::IsPermitted(prop, propChars[0], set); return dom::WindowBinding::IsPermitted(prop, propChar0, set);
break; break;
} }
return false; return false;
@ -292,14 +292,15 @@ ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapperArg, jsid idArg, Wr
return false; return false;
} }
JSString *str = desc.value().toString(); JSFlatString *flat = JS_FlattenString(cx, desc.value().toString());
size_t length; if (!flat)
const jschar *chars = JS_GetStringCharsAndLength(cx, str, &length);
if (!chars)
return false; return false;
size_t length = JS_GetStringLength(JS_FORGET_STRING_FLATNESS(flat));
for (size_t i = 0; i < length; ++i) { for (size_t i = 0; i < length; ++i) {
switch (chars[i]) { jschar ch = JS_GetFlatStringCharAt(flat, i);
switch (ch) {
case 'r': case 'r':
if (access & READ) { if (access & READ) {
EnterAndThrow(cx, wrapper, "duplicate 'readable' property flag"); EnterAndThrow(cx, wrapper, "duplicate 'readable' property flag");