glsl: Catch subscripted calls to undeclared subroutines
authorGeorge Barrett <bob@bob131.so>
Sun, 19 Nov 2017 10:55:10 +0000 (21:55 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Mon, 20 Nov 2017 00:04:04 +0000 (11:04 +1100)
generate_array_index fails to check whether the target of a subroutine
call exists in the AST, potentially passing around null ir_rvalue
pointers eventuating in abort/segfault.

Fixes: fd01840c0bd3 ("glsl: add AoA support to subroutines")
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100438

src/compiler/glsl/ast_function.cpp

index d1596c272e654d89d8fabee814ff1a5b076accf2..94e0a16a9c0ef1a3680315e4ca946805345ea309 100644 (file)
@@ -676,8 +676,13 @@ generate_array_index(void *mem_ctx, exec_list *instructions,
       ir_variable *sub_var = NULL;
       *function_name = array->primary_expression.identifier;
 
-      match_subroutine_by_name(*function_name, actual_parameters,
-                               state, &sub_var);
+      if (!match_subroutine_by_name(*function_name, actual_parameters,
+                                    state, &sub_var)) {
+         _mesa_glsl_error(&loc, state, "Unknown subroutine `%s'",
+                          *function_name);
+         *function_name = NULL; /* indicate error condition to caller */
+         return NULL;
+      }
 
       ir_rvalue *outer_array_idx = idx->hir(instructions, state);
       return new(mem_ctx) ir_dereference_array(sub_var, outer_array_idx);