We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1806

Summary: Wrong coding practise in src/video/x11/SDL_x11events.c file, may cause an crash
Product: SDL Reporter: Nitz <nitin.j4>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: 2.0.0   
Hardware: x86   
OS: Linux   

Description Nitz 2013-04-16 02:46:54 UTC
in function,
static void
X11_DispatchEvent(_THIS)
{
  // Some Code

  if (videodata && videodata->windowlist) {
        for (i = 0; i < videodata->numwindows; ++i) {
            if ((videodata->windowlist[i] != NULL) &&
                (videodata->windowlist[i]->xwindow == xevent.xany.window)) {
                data = videodata->windowlist[i];
                break;
            }
        }
    }

  // Some Code
}

In the if condition, if (videodata && videodata->windowlist)
videodata is dereferenced while checking the videodata,
if videodata will be NULL then it may cause an crash.

So videodata should be dereferenced after the NULL check.
Comment 1 Sam Lantinga 2013-04-17 04:41:24 UTC
This does short-circuit evaluation, so if videodata is NULL, the if condition will be false and videodata->windowlist will not be evaluated.

Thanks for checking though!