Bug 124722

Summary: [EFL] X11Helper::createPixmap doesn't initialise out value handleId
Product: WebKit Reporter: Simon Pena <spenap>
Component: WebKit EFLAssignee: Simon Pena <spenap>
Status: RESOLVED FIXED    
Severity: Normal CC: cmarcelo, commit-queue, gyuyoung.kim, kenneth, laszlo.gombos, lucas.de.marchi, luiz, noam, zeno
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch none

Description Simon Pena 2013-11-21 10:12:06 PST
Both 

void X11Helper::createPixmap(Pixmap* handleId, const XVisualInfo& visualInfo, const IntSize& size) and 
void X11Helper::createPixmap(Pixmap* handleId, const EGLint id, bool hasAlpha, const IntSize& size) 

don't initialise the out parameter handleId.

The problem with that is that these functions do early returns under certain error situations, so clients using them could be checking an invalid value for handleId. At the moment, this is only call from EGLXSurface.cpp and GLXSurface.cpp, and while they could initialise themselves the argument before the call, I think that is error prone. I propose doing an early initialisation in createPixmap just to be on the safe side.

Patch following now.
Comment 1 Simon Pena 2013-11-21 10:23:28 PST
Created attachment 217581 [details]
Patch
Comment 2 Gyuyoung Kim 2013-11-25 01:37:51 PST
Comment on attachment 217581 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=217581&action=review

> Source/WebCore/ChangeLog:13
> +        be reliably checked for errors when the function returns.

Though I'm not an expert in this area, I don't understand this description well. one of createPixmap() functions already supports error messages as below.

void X11Helper::createPixmap(Pixmap* handleId, const XVisualInfo& visualInfo, const IntSize& size)
{
    Display* display = nativeDisplay();
    if (!display)
        return;

    if (!visualInfo.visual) {
        LOG_ERROR("Failed to find valid XVisual.");
        return;
    }

    Window xWindow = offscreenRootWindow();
    if (!xWindow) {
        LOG_ERROR("Failed to create offscreen root window.");
        return;
    }

    Pixmap tempHandleId = XCreatePixmap(display, xWindow, size.width(), size.height(), visualInfo.depth);

    if (!tempHandleId) {
        LOG_ERROR("Failed to create offscreen pixmap.");
        return;
    }

    *handleId = tempHandleId;
    XSync(X11Helper::nativeDisplay(), false);

...

If we need to handle error situations for all createPixmap(), aren't we just add error messages in the other function as well ?


Could you explain what is benefit when initializing *handleId ?
Comment 3 Simon Pena 2013-11-25 01:57:11 PST
(In reply to comment #2)
> (From update of attachment 217581 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=217581&action=review
> 
> > Source/WebCore/ChangeLog:13
> > +        be reliably checked for errors when the function returns.
> 
> Though I'm not an expert in this area, I don't understand this description well. one of createPixmap() functions already supports error messages as below.

...

> ...
> 
> If we need to handle error situations for all createPixmap(), aren't we just add error messages in the other function as well ?
> 
> 
> Could you explain what is benefit when initializing *handleId ?

The problem with that approach is that we rely on error messages that will be seen in runtime. Since the function doesn't return false, or give any other hint that it failed, in runtime you cannot really check if everything is going fine.

When properly initialising handleId, the clients consuming the API which are currently doing 

if (!handleId)
   doSomething()

will be able to manage the error in a proper way. At the moment, that kind of checks is wrong: as handleId hasn't been initialised, it can have any value.

So my point is: ensuring handleId is initialised, its clients can safely use it.
Comment 4 Simon Pena 2013-11-25 01:57:50 PST
In my first paragraph, I meant that the error messages go to the console, but you cannot really use them in the logic of the clients using that method.
Comment 5 Gyuyoung Kim 2013-11-25 02:21:33 PST
Comment on attachment 217581 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=217581&action=review

>>> Source/WebCore/ChangeLog:13
>>> +        be reliably checked for errors when the function returns.
>> 
>> Though I'm not an expert in this area, I don't understand this description well. one of createPixmap() functions already supports error messages as below.
>> 
>> void X11Helper::createPixmap(Pixmap* handleId, const XVisualInfo& visualInfo, const IntSize& size)
>> {
>>     Display* display = nativeDisplay();
>>     if (!display)
>>         return;
>> 
>>     if (!visualInfo.visual) {
>>         LOG_ERROR("Failed to find valid XVisual.");
>>         return;
>>     }
>> 
>>     Window xWindow = offscreenRootWindow();
>>     if (!xWindow) {
>>         LOG_ERROR("Failed to create offscreen root window.");
>>         return;
>>     }
>> 
>>     Pixmap tempHandleId = XCreatePixmap(display, xWindow, size.width(), size.height(), visualInfo.depth);
>> 
>>     if (!tempHandleId) {
>>         LOG_ERROR("Failed to create offscreen pixmap.");
>>         return;
>>     }
>> 
>>     *handleId = tempHandleId;
>>     XSync(X11Helper::nativeDisplay(), false);
>> 
>> ...
>> 
>> If we need to handle error situations for all createPixmap(), aren't we just add error messages in the other function as well ?
>> 
>> 
>> Could you explain what is benefit when initializing *handleId ?
> 
> ...

Ok, I understand what concern you point out. Caller can't check if pixmap is null under current implementation. r=me. However, it would be good if graphics folk take a look this finally before landing.
Comment 6 WebKit Commit Bot 2013-11-25 15:53:13 PST
Comment on attachment 217581 [details]
Patch

Clearing flags on attachment: 217581

Committed r159772: <http://trac.webkit.org/changeset/159772>
Comment 7 WebKit Commit Bot 2013-11-25 15:53:16 PST
All reviewed patches have been landed.  Closing bug.