[Static Analysis][Dereference after null check] In function gfxUserFontSet::UserFontCache::Entry::ReportMemory

RESOLVED FIXED in Firefox 49

Status

()

Core
Graphics
RESOLVED FIXED
2 years ago
2 years ago

People

(Reporter: andi, Assigned: andi)

Tracking

(Blocks: 1 bug, {coverity})

Trunk
mozilla49
coverity
Points:
---

Firefox Tracking Flags

(firefox49 fixed)

Details

(Whiteboard: CID 1361619 )

MozReview Requests

()

Submitter Diff Changes Open Issues Last Updated
Loading...
Error loading review requests:

Attachments

(1 attachment)

(Assignee)

Description

2 years ago
The Static Analysis tool Coverity added that variable |mFontEntry| is dereferenced after it's null checked.

Null check:

>>        if (mFontEntry) { // this should always be present
>>            NS_ConvertUTF16toUTF8 familyName(mFontEntry->mFamilyName);
>>            path.AppendPrintf("family=%s", familyName.get());
>>        }

Dereference:

>>    return aCb->
>>        Callback(EmptyCString(), path,
>>                 nsIMemoryReporter::KIND_HEAP, nsIMemoryReporter::UNITS_BYTES,
>>                 mFontEntry->ComputedSizeOfExcludingThis(UserFontsMallocSizeOf),
>>                 NS_LITERAL_CSTRING("Memory used by @font-face resource."),
>>                 aClosure);

As it's imperative that the pointer should have a valid address i suggest eliminating the null check and adding an assert at the beginning of the function.
(Assignee)

Comment 1

2 years ago
Created attachment 8753245 [details]
MozReview Request: Bug 1273409 - add assert for mFontEntry. r?jrmuizel

Review commit: https://reviewboard.mozilla.org/r/53142/diff/#index_header
See other reviews: https://reviewboard.mozilla.org/r/53142/
Attachment #8753245 - Flags: review?(jmuizelaar)
https://reviewboard.mozilla.org/r/53142/#review49946

::: gfx/thebes/gfxUserFontSet.cpp:1308
(Diff revision 1)
>  nsresult
>  gfxUserFontSet::UserFontCache::Entry::ReportMemory(nsIMemoryReporterCallback* aCb,
>                                                     nsISupports* aClosure,
>                                                     bool aAnonymize)
>  {
> +    MOZ_ASSERT(mFontEntry, "mFontEntry shouldn't be null");    

The assertion message here doesn't really add any value; just "MOZ_ASSERT(mFontEntry);" will do.

(And please get rid of the trailing space.)
(Assignee)

Comment 3

2 years ago
Comment on attachment 8753245 [details]
MozReview Request: Bug 1273409 - add assert for mFontEntry. r?jrmuizel

Review request updated; see interdiff: https://reviewboard.mozilla.org/r/53142/diff/1-2/
Attachment #8753245 - Flags: review?(jmuizelaar) → review+
Comment on attachment 8753245 [details]
MozReview Request: Bug 1273409 - add assert for mFontEntry. r?jrmuizel

https://reviewboard.mozilla.org/r/53142/#review50066

NotNull from bug 1272203 would probably help here.

Comment 5

2 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/f4dff50367ba

Comment 6

2 years ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/f4dff50367ba
Status: NEW → RESOLVED
Last Resolved: 2 years ago
status-firefox49: affected → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.