summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2010-02-03 12:42:24 -0700
committerBrian Paul <[email protected]>2010-02-03 15:48:42 -0700
commit60527ff32a23c34f23ae0b22df7130bf56b3dfa5 (patch)
tree5eff8b18bc1cb5c7228dad0a03cfb3dc25f1ecb1
parentd82c37134457263715b8c571827df58ea6789593 (diff)
mesa: check/clamp texture/program matrix accesses
Further testing should reveal if any these assertions are hit...
-rw-r--r--src/mesa/shader/prog_statevars.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/mesa/shader/prog_statevars.c b/src/mesa/shader/prog_statevars.c
index 3a446fd9bb2..20321dd01f6 100644
--- a/src/mesa/shader/prog_statevars.c
+++ b/src/mesa/shader/prog_statevars.c
@@ -302,9 +302,11 @@ _mesa_fetch_state(GLcontext *ctx, const gl_state_index state[],
matrix = &ctx->_ModelProjectMatrix;
}
else if (mat == STATE_TEXTURE_MATRIX) {
+ ASSERT(index < Elements(ctx->TextureMatrixStack));
matrix = ctx->TextureMatrixStack[index].Top;
}
else if (mat == STATE_PROGRAM_MATRIX) {
+ ASSERT(index < Elements(ctx->ProgramMatrixStack));
matrix = ctx->ProgramMatrixStack[index].Top;
}
else if (mat == STATE_COLOR_MATRIX) {
@@ -1075,7 +1077,9 @@ _mesa_load_tracked_matrices(GLcontext *ctx)
mat = ctx->ProjectionMatrixStack.Top;
}
else if (ctx->VertexProgram.TrackMatrix[i] == GL_TEXTURE) {
- mat = ctx->TextureMatrixStack[ctx->Texture.CurrentUnit].Top;
+ GLuint unit = MIN2(ctx->Texture.CurrentUnit,
+ Elements(ctx->TextureMatrixStack) - 1);
+ mat = ctx->TextureMatrixStack[unit].Top;
}
else if (ctx->VertexProgram.TrackMatrix[i] == GL_COLOR) {
mat = ctx->ColorMatrixStack.Top;
@@ -1087,7 +1091,7 @@ _mesa_load_tracked_matrices(GLcontext *ctx)
else if (ctx->VertexProgram.TrackMatrix[i] >= GL_MATRIX0_NV &&
ctx->VertexProgram.TrackMatrix[i] <= GL_MATRIX7_NV) {
GLuint n = ctx->VertexProgram.TrackMatrix[i] - GL_MATRIX0_NV;
- ASSERT(n < MAX_PROGRAM_MATRICES);
+ ASSERT(n < Elements(ctx->ProgramMatrixStack));
mat = ctx->ProgramMatrixStack[n].Top;
}
else {