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 - Wrong coding practise in src/video/x11/SDL_x11events.c file, may cause an crash
Summary: Wrong coding practise in src/video/x11/SDL_x11events.c file, may cause an crash
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.0
Hardware: x86 Linux
: P2 major
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-16 02:46 UTC by Nitz
Modified: 2013-04-17 04:41 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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!