[Mesa-dev] [PATCH shader-db] run: fix crashes with separate shader objects

Marek Olšák maraeo at gmail.com
Wed Aug 17 17:24:10 UTC 2016


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

the text string was not zero-terminated.
---
 run.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/run.c b/run.c
index de815f8..63f933f 100644
--- a/run.c
+++ b/run.c
@@ -634,21 +634,29 @@ main(int argc, char **argv)
             ctx_is_core = type == TYPE_CORE;
 
             /* If there's only one GLSL shader, mark it separable so
              * inputs and outputs aren't eliminated.
              */
             if (num_shaders == 1 && type != TYPE_VP && type != TYPE_FP)
                 use_separate_shader_objects = true;
 
             if (use_separate_shader_objects) {
                 for (unsigned i = 0; i < num_shaders; i++) {
-                    glCreateShaderProgramv(shader[i].type, 1, &shader[i].text);
+                    const char *const_text;
+                    char *text = alloca(shader[i].length + 1);
+
+                    /* Make it zero-terminated. */
+                    memcpy(text, shader[i].text, shader[i].length);
+                    text[shader[i].length] = 0;
+
+                    const_text = text;
+                    glCreateShaderProgramv(shader[i].type, 1, &const_text);
                 }
             } else if (type == TYPE_CORE || type == TYPE_COMPAT) {
                 GLuint prog = glCreateProgram();
 
                 for (unsigned i = 0; i < num_shaders; i++) {
                     GLuint s = glCreateShader(shader[i].type);
                     glShaderSource(s, 1, &shader[i].text, &shader[i].length);
                     glCompileShader(s);
 
                     GLint param;
-- 
2.7.4



More information about the mesa-dev mailing list