Closed Bug 1610606 Opened 5 years ago Closed 5 years ago

Incorrect OOM handling in duck type case in ErrorReport::init()

Categories

(Core :: JavaScript Engine, task, P2)

task

Tracking

()

RESOLVED FIXED
mozilla74
Tracking Status
firefox74 --- fixed

People

(Reporter: mccr8, Assigned: jorendorff)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

As part of investigating bug 1608760, I'm looking at places that could cause JSErrorBase::filename to be null and I think I found one in ErrorReport::init(). One way to create an error object is via duck typing from a regular object that has the fields message, fileName (or filename) and lineNumber.

The code for that includes this:

if (JS_GetProperty(cx, exnObject, filename_str, &val)) {
  RootedString tmp(cx, ToString<CanGC>(cx, val));
  if (tmp) {
    filename = JS_EncodeStringToUTF8(cx, tmp);
...

The first thing JS_EncodeStringToUTF8 does is attempt to linearize tmp, which can fail on OOM. If it does, then filename will be null. I think this should do a null check and fail the entire operation if it happens.

I think it should be possible to trigger this condition with a shell test using oomTest. I'm not sure how to check if fileName is null, but maybe just checking for the empty string is enough.

This code is pretty old, so even if is sort of the cause of bug 1608760, a better fix is probably to make the exception serializing code more robust against a null file name. Who knows what other places might put null in that field.

Priority: -- → P2
Blocks: 1611280
Assignee: nobody → jorendorff
Pushed by jorendorff@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/82d250cf8fab Make js::ErrorReport::init always populate filename on success. r=nbp.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla74
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: