Commit ff5d3dc6 by Corentin Wallez

gl::GetString check for a valid context

glGetString() without a current context could cause a null dereference for some enums. Always return nullptr when no context is bound. BUG=angleproject:1106 Change-Id: Ic36f1adff8b2e3cd54a7b33b2e12899781feba82 Reviewed-on: https://chromium-review.googlesource.com/295142Tested-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 80b2411a
...@@ -2482,44 +2482,50 @@ const GLubyte *GL_APIENTRY GetString(GLenum name) ...@@ -2482,44 +2482,50 @@ const GLubyte *GL_APIENTRY GetString(GLenum name)
Context *context = GetValidGlobalContext(); Context *context = GetValidGlobalContext();
switch (name) if (context)
{ {
case GL_VENDOR: switch (name)
return (GLubyte*)"Google Inc."; {
case GL_VENDOR:
return reinterpret_cast<const GLubyte *>("Google Inc.");
case GL_RENDERER: case GL_RENDERER:
return (GLubyte*)((context != NULL) ? context->getRendererString().c_str() : "ANGLE"); return reinterpret_cast<const GLubyte *>(context->getRendererString().c_str());
case GL_VERSION: case GL_VERSION:
if (context->getClientVersion() == 2) if (context->getClientVersion() == 2)
{ {
return (GLubyte*)"OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")"; return reinterpret_cast<const GLubyte *>(
} "OpenGL ES 2.0 (ANGLE " ANGLE_VERSION_STRING ")");
else }
{ else
return (GLubyte*)"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")"; {
} return reinterpret_cast<const GLubyte *>(
"OpenGL ES 3.0 (ANGLE " ANGLE_VERSION_STRING ")");
}
case GL_SHADING_LANGUAGE_VERSION: case GL_SHADING_LANGUAGE_VERSION:
if (context->getClientVersion() == 2) if (context->getClientVersion() == 2)
{ {
return (GLubyte*)"OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")"; return reinterpret_cast<const GLubyte *>(
} "OpenGL ES GLSL ES 1.00 (ANGLE " ANGLE_VERSION_STRING ")");
else }
{ else
return (GLubyte*)"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")"; {
} return reinterpret_cast<const GLubyte *>(
"OpenGL ES GLSL ES 3.00 (ANGLE " ANGLE_VERSION_STRING ")");
}
case GL_EXTENSIONS: case GL_EXTENSIONS:
return (GLubyte*)((context != NULL) ? context->getExtensionString().c_str() : ""); return reinterpret_cast<const GLubyte *>(context->getExtensionString().c_str());
default: default:
if (context)
{
context->recordError(Error(GL_INVALID_ENUM)); context->recordError(Error(GL_INVALID_ENUM));
return nullptr;
} }
return NULL;
} }
return nullptr;
} }
void GL_APIENTRY GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params) void GL_APIENTRY GetTexParameterfv(GLenum target, GLenum pname, GLfloat* params)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment