<div dir="ltr">Patch is:<div>Tested-by: Bartosz Tomczyk <<a href="mailto:bartosz.tomczyk86@gmail.com">bartosz.tomczyk86@gmail.com</a>></div><div><br></div><div>I can confirm it fix use-after-free issue.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Feb 7, 2017 at 1:47 PM, Samuel Iglesias Gonsálvez <span dir="ltr"><<a href="mailto:siglesias@igalia.com" target="_blank">siglesias@igalia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">The get_variable_being_redeclared(<wbr>) function can free 'var' because<br>
a re-declaration of an unsized array variable can establish the size, so<br>
we set the array type to the 'earlier' declaration and free 'var' as it is<br>
not needed anymore.<br>
<br>
However, the same 'var' is referenced later in ast_declarator_list::hir().<br>
<br>
</span>This patch fixes it by assign the pointer 'var' to the pointer 'earlier'.<br>
<span class=""><br>
This error was detected by Address Sanitizer.<br>
<br>
</span>v2:<br>
<br>
* Pointer-to-pointer assignment (Bartosz Tomczyk)<br>
<span class=""><br>
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=99677" rel="noreferrer" target="_blank">https://bugs.freedesktop.org/<wbr>show_bug.cgi?id=99677</a><br>
Signed-off-by: Samuel Iglesias Gonsálvez <<a href="mailto:siglesias@igalia.com">siglesias@igalia.com</a>><br>
---<br>
<br>
</span>Another possibility is to use reference-to-pointer but it is a C++<br>
thing. IIRC, we agreed on avoiding C++-specific features to make it<br>
easy for C developers, but I have no strong opinion for either option.<br>
<br>
 src/compiler/glsl/ast_to_hir.<wbr>cpp | 10 ++++++----<br>
 1 file changed, 6 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/src/compiler/glsl/ast_to_<wbr>hir.cpp b/src/compiler/glsl/ast_to_<wbr>hir.cpp<br>
index b31b61d1ed6..93ba1d510fa 100644<br>
--- a/src/compiler/glsl/ast_to_<wbr>hir.cpp<br>
+++ b/src/compiler/glsl/ast_to_<wbr>hir.cpp<br>
@@ -3958,10 +3958,12 @@ apply_type_qualifier_to_<wbr>variable(const struct ast_type_qualifier *qual,<br>
  * is a redeclaration, \c NULL otherwise.<br>
  */<br>
 static ir_variable *<br>
-get_variable_being_<wbr>redeclared(ir_variable *var, YYLTYPE loc,<br>
+get_variable_being_<wbr>redeclared(ir_variable **var_pointer, YYLTYPE loc,<br>
<span class="">                               struct _mesa_glsl_parse_state *state,<br>
                               bool allow_all_redeclarations)<br>
</span> {<br>
+   ir_variable *var = *var_pointer;<br>
+<br>
    /* Check if this declaration is actually a re-declaration, either to<br>
     * resize an array or add qualifiers to an existing variable.<br>
     *<br>
@@ -3999,7 +4001,7 @@ get_variable_being_redeclared(<wbr>ir_variable *var, YYLTYPE loc,<br>
<span class=""><br>
       earlier->type = var->type;<br>
       delete var;<br>
-      var = NULL;<br>
</span>+      *var_pointer = earlier;<br>
<span class="">    } else if ((state->ARB_fragment_coord_<wbr>conventions_enable ||<br>
               state->is_version(150, 0))<br>
               && strcmp(var->name, "gl_FragCoord") == 0<br>
</span>@@ -5207,7 +5209,7 @@ ast_declarator_list::hir(exec_<wbr>list *instructions,<br>
       bool var_is_gl_id = is_gl_identifier(var->name);<br>
<br>
       ir_variable *earlier =<br>
-         get_variable_being_redeclared(<wbr>var, decl->get_location(), state,<br>
+         get_variable_being_redeclared(<wbr>&var, decl->get_location(), state,<br>
                                        false /* allow_all_redeclarations */);<br>
       if (earlier != NULL) {<br>
          if (var_is_gl_id &&<br>
@@ -7873,7 +7875,7 @@ ast_interface_block::hir(exec_<wbr>list *instructions,<br>
<br>
          if (redeclaring_per_vertex) {<br>
             ir_variable *earlier =<br>
-               get_variable_being_redeclared(<wbr>var, loc, state,<br>
+               get_variable_being_redeclared(<wbr>&var, loc, state,<br>
                                              true /* allow_all_redeclarations */);<br>
             if (!var_is_gl_id || earlier == NULL) {<br>
                _mesa_glsl_error(&loc, state,<br>
<div class="HOEnZb"><div class="h5">--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>