Closed Bug 1322146 Opened 8 years ago Closed 7 years ago

ClassInfoData constructor does not initialize mFlags (initialized lazily later)

Categories

(Core :: Security: CAPS, defect)

50 Branch
x86
Windows 10
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla53
Tracking Status
firefox53 --- fixed

People

(Reporter: jeanluc.bonnafoux, Assigned: jeanluc.bonnafoux)

Details

(Whiteboard: [lang=c++])

Attachments

(1 file)

User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0
Build ID: 20161129173726

Steps to reproduce:

In file nsScriptsSecurityManager.cpp, line 164 the constructor:
 
ClassInfoData(nsIClassInfo *aClassInfo, const char *aName)
        : mClassInfo(aClassInfo),
          mName(const_cast<char *>(aName)),
          mDidGetFlags(false),
          mMustFreeName(false)
    {
    }

does not initialize the member variable: mFlags



Expected results:

This member viariable should be initialized at constructor level in my opinion.
Whiteboard: [lang=c++]
OS: Unspecified → Windows 10
Hardware: Unspecified → x86
Component: Untriaged → Security: CAPS
Product: Firefox → Core
Hello,

I don't think codes generates an issue.

ClassInfoData is used only once here in nsScriptsSecurityManager.cpp, line 1195

ClassInfoData objClassInfo = ClassInfoData(aClassInfo, nullptr);
if (objClassInfo.IsDOMClass())
{
        return NS_OK;
}

where IsDOMClass() will trigger call to GetFlags() method.
Since constructor of ClassInfoData sets data member mDidGetFlags to false, the mFlags data member will be set by the call to:
nsresult rv = mClassInfo->GetFlags(&mFlags); line 182

IMHO, it is a good thing to initialize all data members in constructors.
I am also wondering why we a a full 'helper class' in a .cpp file.

Thanks,
Flags: needinfo?(dveditz)
Hello,

Could you please assign me to this issue ?

Any comments on this member variable not initialized in constructor ?

Thanks,
Hello,

How could we move forward on this case ?

Thanks,
That field is initialized lazi
(In reply to Emilio Cobos Álvarez [:emilio] from comment #4)
> That field is initialized lazi

Sorry (too much context-switching).

I meant... As discussed on IRC, that field is initialized lazily and not used without initialization, so it's not a bug. The reporter would like to submit a patch to simplify that code though, so I guess we can leave this open until that happens.
Attachment #8819854 - Flags: review?(emilio+bugs)
Comment on attachment 8819854 [details] [diff] [review]
initialize mFlags variable in constructor

Review of attachment 8819854 [details] [diff] [review]:
-----------------------------------------------------------------

The patch looks ok to me, but I'd also take time to simplify GetFlags, otherwise the patch doesn't make as much sense I think.

Also, the patch can't technically land just with my review I think, but I'll find someone to redirect the review when the patch is updated.

Clearing the review flag for now. Feel free to flag me again when the patch is updated.

Thanks! :)
Attachment #8819854 - Flags: review?(emilio+bugs)
Assignee: nobody → jeanluc.bonnafoux
Flags: needinfo?(dveditz)
Summary: ClassInfoData constructor does not initialize mFlags → ClassInfoData constructor does not initialize mFlags (initialized lazily later)
Comment on attachment 8819854 [details] [diff] [review]
initialize mFlags variable in constructor

Can't hurt. Currently we don't need it because it's initialized before being used, but this could prevent future problems if that ever changes.

r=dveditz
Attachment #8819854 - Flags: review+
Keywords: checkin-needed
Pushed by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/cad5f47a08b7
initialize mFlags variable in constructor. r=dveditz
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/cad5f47a08b7
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla53
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: