Closed Bug 1278480 Opened 8 years ago Closed 8 years ago

[Static Analysis][Dereference null return value] In function TouchActionHelper::GetAllowedTouchBehavior

Categories

(Core :: Graphics, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla50
Tracking Status
firefox50 --- fixed

People

(Reporter: andi, Assigned: andi)

References

(Blocks 1 open bug)

Details

(Keywords: coverity, Whiteboard: CID 1362528)

Attachments

(1 file)

The Static Analysis tool Coverity detected that pointer |view| be assigned a null return value:

>>  nsView *view = nsView::GetViewFor(aWidget);
>>  nsIFrame *viewFrame = view->GetFrame();

|view| should be checked with an assert before being used since in function GetFrame member variable |mFrame| will be return thus producing a null pointer dereference. 

>>  nsView *view = nsView::GetViewFor(aWidget);
>>  MOZ_ASSERT(view, "view should not be null");
>>  nsIFrame *viewFrame = view->GetFrame();
Comment on attachment 8760637 [details]
Bug 1278480 - prevent null pointer dereference.

I think this should either handle nullptr properly or have a comment explaining why it won't get a nullptr.
Attachment #8760637 - Flags: review?(jmuizelaar) → review?(bugmail.mozilla)
Attachment #8760637 - Flags: review?(bugmail.mozilla) → review-
Comment on attachment 8760637 [details]
Bug 1278480 - prevent null pointer dereference.

https://reviewboard.mozilla.org/r/58182/#review55068

I think in this case adding a null check would be more correct. I don't think there's any guarantee here that the view will be non-null. You can move the |TouchBehaviorFlags behavior = ...| line near the bottom of the function up to the top and return that as the value if the view is null.
Comment on attachment 8760637 [details]
Bug 1278480 - prevent null pointer dereference.

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/58182/diff/1-2/
Attachment #8760637 - Flags: review- → review?(bugmail.mozilla)
Comment on attachment 8760637 [details]
Bug 1278480 - prevent null pointer dereference.

https://reviewboard.mozilla.org/r/58182/#review55370

::: gfx/layers/apz/util/TouchActionHelper.cpp:54
(Diff revision 2)
>    nsView *view = nsView::GetViewFor(aWidget);
> +  TouchBehaviorFlags behavior = AllowedTouchBehavior::VERTICAL_PAN | AllowedTouchBehavior::HORIZONTAL_PAN |
> +                                AllowedTouchBehavior::PINCH_ZOOM | AllowedTouchBehavior::DOUBLE_TAP_ZOOM;
> +
> +  if (!view)
> +    return behavior;

Braces around the body of the if statement, please. r+ with that.
Attachment #8760637 - Flags: review?(bugmail.mozilla) → review+
Comment on attachment 8760637 [details]
Bug 1278480 - prevent null pointer dereference.

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/58182/diff/2-3/
Comment on attachment 8760637 [details]
Bug 1278480 - prevent null pointer dereference.

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/58182/diff/3-4/
https://hg.mozilla.org/mozilla-central/rev/ec866ebf94bc
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: