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 3720 - SDL_GL_GetAttribute doesn't check for initialized video driver
Summary: SDL_GL_GetAttribute doesn't check for initialized video driver
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: All All
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-31 15:01 UTC by Simon Hug
Modified: 2017-07-31 19:57 UTC (History)
0 users

See Also:


Attachments
Patch that fixes a possible NULL-pointer indirection in SDL_GL_GetAttribute. (1.05 KB, patch)
2017-07-31 15:01 UTC, Simon Hug
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hug 2017-07-31 15:01:49 UTC
Created attachment 2813 [details]
Patch that fixes a possible NULL-pointer indirection in SDL_GL_GetAttribute.

SDL_GL_GetAttribute doesn't check if a video driver has been initialized and will access the SDL_VideoDevice pointer, which is NULL at that point.

I think all of the attributes require an initialized driver, so a simple NULL check should fix it. Patch is attached.

Test case:

#include <SDL.h>

int main(int argc, char*argv[])
{
    int val, res;

    res = SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &val);
    if (res != 0)
        SDL_Log("Error getting attribute before init (%d): %s\n", res, SDL_GetError());
    else
        SDL_Log("Major version set to %d\n", val);

    res = SDL_Init(SDL_INIT_VIDEO);
    if (res != 0)
        SDL_Log("Error initializing SDL (%d): %s\n", res, SDL_GetError());

    res = SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &val);
    if (res != 0)
        SDL_Log("Error getting attribute after init (%d): %s\n", res, SDL_GetError());
    else
        SDL_Log("Major version set to %d\n", val);

    SDL_Quit();
    return 0;
}
Comment 1 Sam Lantinga 2017-07-31 19:57:29 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/6f6e8880cd37