Closed Bug 1232635 Opened 10 years ago Closed 10 years ago

[Static Analysis][Dereference before null check] In function FrameLayerBuilder::DrawPaintedLayer from FrameLayerBuilder.cpp

Categories

(Core :: Layout, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla47
Tracking Status
firefox46 --- affected
firefox47 --- fixed

People

(Reporter: andi, Assigned: andi)

References

(Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: CID 1338377 )

Attachments

(1 file, 1 obsolete file)

The Static Analysis tool Coverity added that presContext is dereferenced before being null checked. dereference: >> // PaintedLayers. If aDirtyRegion has not changed since the previous call >> // then we can skip this. >> int32_t appUnitsPerDevPixel = presContext->AppUnitsPerDevPixel(); >> RecomputeVisibilityForItems(entry->mItems, builder, aDirtyRegion, >> offset, appUnitsPerDevPixel, >> userData->mXScale, userData->mYScale); >> userData->mVisibilityComputedRegion = aDirtyRegion; null check: >> if (presContext && presContext->GetDocShell() && isActiveLayerManager) { >> nsDocShell* docShell = static_cast<nsDocShell*>(presContext->GetDocShell()); >> RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get(); The null check is done after the dereference was made. if we expect that the normal behavior of this functios is to always have a valid presContext we should add an assert checking it's validity thus letting know Coverity that this is the intended behavior.
Attached patch Bug 1232635.diff (obsolete) — Splinter Review
Attachment #8698411 - Flags: review?(dbaron)
Comment on attachment 8698411 [details] [diff] [review] Bug 1232635.diff Coverity should know that PresContext() never returns a null pointer without this. We should fix that problem rather than adding this assertion.
Attachment #8698411 - Flags: review?(dbaron) → review-
What actually confused Coveirty was this check: >> if (presContext && presContext->GetDocShell() && isActiveLayerManager) { >> nsDocShell* docShell = static_cast<nsDocShell*>(presContext->GetDocShell()); >> RefPtr<TimelineConsumers> timelines = TimelineConsumers::Get(); Testing the validity of presContext determined Coverity to assume that it could also be NULL so that's why it triggered dereference before null check. So should this be treated as not a bug?
Flags: needinfo?(dbaron)
I think the correct fix here is to remove the useless null check here: > if (presContext && presContext->GetDocShell() && isActiveLayerManager) { We always promise the return value of PresContext() is not null, but Coverity deduces that presContext could be null from this line.
yes this is what i was thinking as well.
Attached patch Bug 1232635.diffSplinter Review
Attachment #8698411 - Attachment is obsolete: true
Attachment #8699376 - Flags: review?(dbaron)
Comment on attachment 8699376 [details] [diff] [review] Bug 1232635.diff Review of attachment 8699376 [details] [diff] [review]: ----------------------------------------------------------------- As David is probably very busy
Attachment #8699376 - Flags: review?(dbaron) → review?(bzbarsky)
Flags: needinfo?(dbaron)
Comment on attachment 8699376 [details] [diff] [review] Bug 1232635.diff r=me, but Xidorn could totally have reviewed this.
Attachment #8699376 - Flags: review?(bzbarsky) → review+
But I'm totally not a peer :/
OK, but I am, and I just totally delegated you to review patches like that if you're comfortable with them. ;)
OK, hopefully I won't ruin the code :)
Keywords: checkin-needed
Flags: needinfo?(bogdan.postelnicu)
This is only a null check and should't this be the issue.
Flags: needinfo?(bogdan.postelnicu)
Keywords: checkin-needed
> backout for test failures like https://hg.mozilla.org/integration/mozilla-inbound/rev/b6ac829c36bb That's not a link to a test failure... what were the actual failures? I'm not seeing them on https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&revision=88e44bfba483 but maybe they only showed up later?
Flags: needinfo?(cbook)
I think the crash is associated with this bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1247122
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla47
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: