Closed Bug 1536738 Opened 6 years ago Closed 6 years ago

`this` in methods marked as MOZ_CAN_RUN_SCRIPT is not considered as safe

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

defect
Not set
normal

Tracking

(firefox68 affected)

RESOLVED INVALID
Tracking Status
firefox68 --- affected

People

(Reporter: masayuki, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Foo::MozCanRunScript() {
  mBar->MaybeCanRunScript(this);
}

is considered as not safe. I.e., it seems that the following two code blocks might be considered as different:

Foo::MozCanRunScript() {
  AnotherCanRunScript();
}
Foo::MozCanRunScript() {
  this->AnotherCanRunScript();
}

When MozCanRunScript() is called, the instance of Foo should be grabbed with local RefPtr or something. Therefore, this in MOZ_CAN_RUN_SCRIPT methods should be safe.

Component: DOM: Core & HTML → XPCOM
>Foo::MozCanRunScript() {
>  mBar->MaybeCanRunScript(this);
>}

This would be considered unsafe because it's using mBar, which might get nulled out by the script running.

We don't seem to have explicit tests for the "this->AnotherCanRunScript()" case, but I just added one and it passes. I'll attach that here, but could you please double-check whether the problem you're actually running into is with "this" or with mBar?

Flags: needinfo?(masayuki)
Attached patch Automated testcase (deleted) — Splinter Review

I'm going to sneak this testcase into some other changes I'm making to the static analysis anyway.

Component: XPCOM → Source Code Analysis
Product: Core → Firefox Build System

(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #1)

We don't seem to have explicit tests for the "this->AnotherCanRunScript()" case, but I just added one and it passes. I'll attach that here, but could you please double-check whether the problem you're actually running into is with "this" or with mBar?

Oh, right. I confirmed that ^ is under the "m" of "mBar". Sorry for taking your time.

Status: NEW → RESOLVED
Closed: 6 years ago
Flags: needinfo?(masayuki)
Resolution: --- → INVALID
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: