Closed
Bug 619255
Opened 15 years ago
Closed 15 years ago
GC hazard in JO() from json.cpp due to reuse of root (1.9.[12]-only)
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
DUPLICATE
of bug 616009
People
(Reporter: igor, Assigned: igor)
Details
(Keywords: verified1.9.1, verified1.9.2, Whiteboard: [sg:dupe 616009])
Attachments
(2 files)
841 bytes,
patch
|
gal
:
review+
christian
:
approval1.9.2.14+
|
Details | Diff | Splinter Review |
880 bytes,
patch
|
christian
:
approval1.9.1.17+
|
Details | Diff | Splinter Review |
On 1.9.2 branch JO() from json.cpp incorrectly reuse the passed vp parameter for rooting an iterator leading to a GC hazard. The following example demonstrates this for a debug build of JS shell:
function iter() {
({});
gc();
yield 1;
}
function create_iter() {
return iter();
}
JSON.stringify({ get o() {
var obj = {};
obj.__iterator__ = create_iter;
return obj;
}});
~/m/192/js/src> ~/b/js/192dbg32/js ~/s/x.js
Segmentation fault (core dumped)
On trunk we are safe due to the conservative GC scanner.
Assignee | ||
Comment 1•15 years ago
|
||
The patch copies the initial value of *vp into an extra root.
Attachment #497715 -
Flags: review?(gal)
Comment 2•15 years ago
|
||
Comment on attachment 497715 [details] [diff] [review]
fix
>diff --git a/js/src/json.cpp b/js/src/json.cpp
>--- a/js/src/json.cpp
>+++ b/js/src/json.cpp
>@@ -241,20 +241,20 @@ WriteIndent(JSContext *cx, StringifyCont
>
> static JSBool
> JO(JSContext *cx, jsval *vp, StringifyContext *scx)
> {
> JSObject *obj = JSVAL_TO_OBJECT(*vp);
>
> if (!scx->cb.append('{'))
> return JS_FALSE;
>
>- jsval vec[3] = {JSVAL_NULL, JSVAL_NULL, JSVAL_NULL};
>- JSAutoTempValueRooter tvr(cx, 3, vec);
>+ jsval vec[] = {JSVAL_NULL, JSVAL_NULL, JSVAL_NULL, *vp};
>+ JSAutoTempValueRooter tvr(cx, JS_ARRAY_LENGTH(vec), vec);
> jsval& key = vec[0];
> jsval& outputValue = vec[1];
>
> JSObject *iterObj = NULL;
> jsval *keySource = vp;
> bool usingWhitelist = false;
>
> // if the replacer is an array, we use the keys from it
> if (scx->replacer && JS_IsArrayObject(cx, scx->replacer)) {
Attachment #497715 -
Flags: review?(gal) → review+
Assignee | ||
Updated•15 years ago
|
Attachment #497715 -
Flags: approval1.9.2.14?
Assignee | ||
Comment 3•15 years ago
|
||
Nominating for 1.9.2 due to the critical status.
blocking1.9.2: --- → ?
Whiteboard: [sg:critical]
Does this affect 1.9.1 as well?
Assignee | ||
Comment 6•15 years ago
|
||
(In reply to comment #4)
> Does this affect 1.9.1 as well?
Yes, this affects 1.9.1 - I forgot that the native JSON were introduced on that branch first.
Assignee | ||
Comment 7•15 years ago
|
||
191 version of the patch needed a trivial merge. Here is a plain diff between patches:
/home/igor/s/> diff json_bug619255.patch json_bug619255_191.patch
4,5c4
< @@ -241,20 +241,20 @@ WriteIndent(JSContext *cx, StringifyCont
<
---
> @@ -261,20 +261,20 @@ WriteIndent(JSContext *cx, StringifyCont
11c10,11
< if (!scx->cb.append('{'))
---
> jschar c = jschar('{');
> if (!scx->callback(&c, 1, scx->data))
Attachment #498868 -
Flags: approval1.9.1.17?
Comment on attachment 497715 [details] [diff] [review]
fix
a=LegNeato for 1.9.2.14
Attachment #497715 -
Flags: approval1.9.2.14? → approval1.9.2.14+
Comment on attachment 498868 [details] [diff] [review]
fix for 191
a=LegNeato for 1.9.1.17
Attachment #498868 -
Flags: approval1.9.1.17? → approval1.9.1.17+
Updated•15 years ago
|
blocking2.0: --- → -
Updated•15 years ago
|
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → DUPLICATE
Updated•15 years ago
|
Whiteboard: [sg:critical] → [sg:dupe 616009]
Assignee | ||
Updated•15 years ago
|
Summary: GC hazard in JO() from json.cpp due to reuse of root (1.9.2-only) → GC hazard in JO() from json.cpp due to reuse of root (1.9.[12]-only)
Updated•15 years ago
|
status1.9.1:
--- → .17-fixed
status1.9.2:
--- → .14-fixed
Comment 11•14 years ago
|
||
Verified for branches by verifying bug 616009.
Keywords: verified1.9.1,
verified1.9.2
Updated•14 years ago
|
Group: core-security
You need to log in
before you can comment on or make changes to this bug.
Description
•