| Summary: | SDL_GL_GetAttribute doesn't check for initialized video driver | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Simon Hug <chli.hug> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: | Patch that fixes a possible NULL-pointer indirection in SDL_GL_GetAttribute. | ||
Fixed, thanks! https://hg.libsdl.org/SDL/rev/6f6e8880cd37 |
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; }