diff options
author | José Fonseca <jfonseca@vmware.com> | 2015-02-05 16:34:21 +0000 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2015-02-06 11:16:27 +0000 |
commit | 76f49b74243c3d2a6469e3ee13796d03741915f2 (patch) | |
tree | 8ee052f9a0a5393fd8b04535b10ce163935bb739 | |
parent | 22a850da47b94bd6c1802ecba9f5cde19f2b2807 (diff) |
gltrace: Prevent NULL derreference when glGetIntegerv(params=NULL).
This can and does happen as explained in the code comment.
-rw-r--r-- | wrappers/glcaps.cpp | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/wrappers/glcaps.cpp b/wrappers/glcaps.cpp index 742e26a7..7ffff2d6 100644 --- a/wrappers/glcaps.cpp +++ b/wrappers/glcaps.cpp @@ -196,16 +196,37 @@ _glGetString_override(GLenum name) } +static void +getInteger(const configuration *config, + GLenum pname, GLint *params) +{ + if (params) { + *params = getConfigInteger(config, pname); + if (*params != 0) { + return; + } + } + + // Ask the real GL library + _glGetIntegerv(pname, params); +} + + void _glGetIntegerv_override(GLenum pname, GLint *params) { const configuration *config = getConfig(); - *params = getConfigInteger(config, pname); - if (*params == 0) { - // Ask the real GL library - _glGetIntegerv(pname, params); - } + /* + * It's important to handle params==NULL correctly here, which can and does + * happen, particularly when pname is GL_COMPRESSED_TEXTURE_FORMATS or + * GL_PROGRAM_BINARY_FORMATS and the implementation returns 0 for + * GL_NUM_COMPRESSED_TEXTURE_FORMATS or GL_NUM_PROGRAM_BINARY_FORMATS, as + * the application ends up calling `params = malloc(0)` or `param = new + * GLint[0]` which can yield NULL. + */ + + getInteger(config, pname, params); if (params) { const Context *ctx; @@ -245,12 +266,7 @@ _glGetStringi_override(GLenum name, GLuint index) { const ExtensionsDesc *desc = getExtraExtensions(ctx); GLint numExtensions = 0; - if (config) { - numExtensions = getConfigInteger(config, GL_NUM_EXTENSIONS); - } - if (numExtensions == 0) { - _glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); - } + getInteger(config, GL_NUM_EXTENSIONS, &numExtensions); if ((GLuint)numExtensions <= index && index < (GLuint)numExtensions + desc->numStrings) { return (const GLubyte *)desc->strings[index - (GLuint)numExtensions]; } |