Skip to content

Commit a7a99fa

Browse files
committed
Added Rooting to avoid GC Hazards
Based on the GC Hazard analysis I fixed some of the dangerous code paths that was flagged.
1 parent 8295fe8 commit a7a99fa

File tree

6 files changed

+9
-9
lines changed

6 files changed

+9
-9
lines changed

js/src/builtin/Array.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ bool js::array_join(JSContext* cx, unsigned argc, Value* vp) {
13761376
}
13771377

13781378
// Step 8.
1379-
JSString* str = sb.finishString();
1379+
JS::Rooted<JSString*> str(cx, sb.finishString());
13801380
if (!str) {
13811381
return false;
13821382
}

js/src/builtin/JSON.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2358,7 +2358,7 @@ bool json_stringify(JSContext* cx, unsigned argc, Value* vp) {
23582358
// needs to support returning undefined. So this is a little awkward
23592359
// for the API, because we want to support streaming writers.
23602360
if (!sb.empty()) {
2361-
JSString* str = sb.finishString();
2361+
JS::Rooted<JSString*> str(cx, sb.finishString());
23622362
if (!str) {
23632363
return false;
23642364
}

js/src/builtin/String.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ static bool str_escape(JSContext* cx, unsigned argc, Value* vp) {
526526
return true;
527527
}
528528

529-
JSString* res = newChars.toString(cx, newLength);
529+
JS::Rooted<JSString*> res(cx, newChars.toString(cx, newLength));
530530
if (!res) {
531531
return false;
532532
}
@@ -1969,7 +1969,7 @@ static bool str_normalize(JSContext* cx, unsigned argc, Value* vp) {
19691969
form = NormalizationForm::NFC;
19701970
} else {
19711971
// Step 4.
1972-
JSLinearString* formStr = ArgToLinearString(cx, args, 0);
1972+
JS::Rooted<JSLinearString*> formStr(cx, ArgToLinearString(cx, args, 0));
19731973
if (!formStr) {
19741974
return false;
19751975
}
@@ -3312,7 +3312,7 @@ static JSLinearString* TrimString(JSContext* cx, JSString* str, bool trimStart,
33123312
&end);
33133313
}
33143314

3315-
JSLinearString* result = NewDependentString(cx, linear, begin, end - begin);
3315+
JS::Rooted<JSLinearString*> result(cx, NewDependentString(cx, linear, begin, end - begin));
33163316

33173317
// TaintFox: Add trim operation to current taint flow.
33183318
// the acutal trimming of taint ranges has been done in
@@ -4293,7 +4293,7 @@ static ArrayObject* CharSplitHelper(JSContext* cx, Handle<JSLinearString*> str,
42934293

42944294
for (size_t i = 0; i < resultlen; ++i) {
42954295
// TaintFox: code modified to avoid atoms.
4296-
JSString* sub = NewDependentString(cx, str, i, 1);
4296+
JS::Rooted<JSString*> sub(cx, NewDependentString(cx, str, i, 1));
42974297
// was:
42984298
// JSString* sub = staticStrings.getUnitStringForElement(cx, str, i);
42994299
if (!sub) {

js/src/jit/VMFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ JSString* StringReplace(JSContext* cx, HandleString string,
13571357
MOZ_ASSERT(pattern);
13581358
MOZ_ASSERT(repl);
13591359
// Foxhound: this will propagate the taint but not add the operation
1360-
JSString* str = str_replace_string_raw(cx, string, pattern, repl);
1360+
Rooted<JSString*> str(cx, str_replace_string_raw(cx, string, pattern, repl));
13611361
if (str && str->taint().hasTaint()) {
13621362
str->taint().extend(TaintOperationFromContext(cx, "replace", true, pattern, repl));
13631363
}

js/src/jsapi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5014,7 +5014,7 @@ JS_ReportTaintSink(JSContext* cx, JS::HandleString str, const char* sink, JS::Ha
50145014
// slot of the current global object.
50155015
RootedFunction report(cx);
50165016

5017-
JSObject* global = cx->global();
5017+
JS::Rooted<JSObject*> global(cx, cx->global());
50185018

50195019
RootedValue slot(cx, JS::GetReservedSlot(global, TAINT_REPORT_FUNCTION_SLOT));
50205020
if (slot.isUndefined()) {

js/src/jstaint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ void JS::PrintJsonTaint(JSContext* cx, JSString* str, HandleValue location, js::
504504

505505
// Dump additional information from the taintreport
506506
if (location.isObject()) {
507-
JSObject* obj = ToObject(cx, location);
507+
JS::Rooted<JSObject*> obj(cx, ToObject(cx, location));
508508
PrintJsonObject(cx, obj, json);
509509
}
510510

0 commit comments

Comments
 (0)