[Mesa-dev] [PATCH 4/6] glsl_to_tgsi: add assertions for detecting out-of-bounds immediates access

Marek Olšák maraeo at gmail.com
Sat Apr 11 12:12:32 PDT 2015


From: Marek Olšák <marek.olsak at amd.com>

---
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 00d8785..26d859e 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4348,6 +4348,7 @@ struct st_translate {
    struct ureg_src *constants;
    int num_constants;
    struct ureg_src *immediates;
+   int num_immediates;
    struct ureg_dst outputs[PIPE_MAX_SHADER_OUTPUTS];
    struct ureg_src inputs[PIPE_MAX_SHADER_INPUTS];
    struct ureg_dst address[3];
@@ -4568,6 +4569,7 @@ src_register(struct st_translate *t, const st_src_reg *reg)
                   t->constants[reg->index] : ureg_imm4f(t->ureg, 0, 0, 0, 0);
 
    case PROGRAM_IMMEDIATE:
+      assert(reg->index >= 0 && reg->index < t->num_immediates);
       return t->immediates[reg->index];
 
    case PROGRAM_INPUT:
@@ -4688,6 +4690,7 @@ translate_tex_offset(struct st_translate *t,
 
    switch (in_offset->file) {
    case PROGRAM_IMMEDIATE:
+      assert(in_offset->index >= 0 && in_offset->index < t->num_immediates);
       imm_src = t->immediates[in_offset->index];
 
       offset.File = imm_src.File;
@@ -5333,6 +5336,8 @@ st_translate_program(
       ret = PIPE_ERROR_OUT_OF_MEMORY;
       goto out;
    }
+   t->num_immediates = program->num_immediates;
+
    i = 0;
    foreach_in_list(immediate_storage, imm, &program->immediates) {
       assert(i < program->num_immediates);
@@ -5384,6 +5389,7 @@ out:
       free(t->constants);
       t->num_constants = 0;
       free(t->immediates);
+      t->num_immediates = 0;
 
       if (t->error) {
          debug_printf("%s: translate error flag set\n", __FUNCTION__);
-- 
2.1.0



More information about the mesa-dev mailing list