mesa: fix out of bounds access in glGetFramebufferParameterivEXT

ColorDrawBuffer is an array of MAX_DRAW_BUFFERS == 8.

Found by Coverity.

Signed-off-by: Marcin Ślusarz <marcin.slusarz@intel.com>
Fixes: 7534c536ca ("mesa: add EXT_dsa (Named)Framebuffer functions")
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6067>
(cherry picked from commit 0906d5d504)
This commit is contained in:
Marcin Ślusarz 2020-07-24 19:19:07 +02:00 committed by Eric Engestrom
parent f2de23e785
commit 3af72354fe
2 changed files with 6 additions and 2 deletions

View file

@ -1786,7 +1786,7 @@
"description": "mesa: fix out of bounds access in glGetFramebufferParameterivEXT",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"master_sha": null,
"because_sha": "7534c536ca0f4b2b123200f421460094034f37a3"
},

View file

@ -4814,7 +4814,11 @@ _mesa_GetFramebufferParameterivEXT(GLuint framebuffer, GLenum pname,
*param = fb->ColorReadBuffer;
}
else if (GL_DRAW_BUFFER0 <= pname && pname <= GL_DRAW_BUFFER15) {
*param = fb->ColorDrawBuffer[pname - GL_DRAW_BUFFER0];
unsigned buffer = pname - GL_DRAW_BUFFER0;
if (buffer < ARRAY_SIZE(fb->ColorDrawBuffer))
*param = fb->ColorDrawBuffer[buffer];
else
_mesa_error(ctx, GL_INVALID_ENUM, "glGetFramebufferParameterivEXT(pname)");
}
else {
_mesa_error(ctx, GL_INVALID_ENUM, "glGetFramebufferParameterivEXT(pname)");