Mesa (7.10): glcpp: Fix segfault when validating macro redefinitions

Ian Romanick idr at kemper.freedesktop.org
Mon Jan 17 16:28:43 PST 2011


Module: Mesa
Branch: 7.10
Commit: c2b721bc0e83bc6c43fd9a2f52185b7772346975
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c2b721bc0e83bc6c43fd9a2f52185b7772346975

Author: Chad Versace <chad.versace at intel.com>
Date:   Mon Jan 10 16:55:17 2011 -0800

glcpp: Fix segfault when validating macro redefinitions

In _token_list_equal_ignoring_space(token_list_t*, token_list_t*), add
a guard that prevents dereferncing a null token list.

This fixes test src/glsl/glcpp/tests/092-redefine-macro-error-2.c and
Bugzilla #32695.
(cherry picked from commit 4fff52f1c973f2f284c142fbb31536a9656767c9)

---

 src/glsl/glcpp/glcpp-parse.y |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 558ad0a..148b0ff 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -825,10 +825,31 @@ _token_list_trim_trailing_space (token_list_t *list)
 }
 
 int
+_token_list_is_empty_ignoring_space (token_list_t *l)
+{
+	token_node_t *n;
+
+	if (l == NULL)
+		return 1;
+
+	n = l->head;
+	while (n != NULL && n->token->type == SPACE)
+		n = n->next;
+
+	return n == NULL;
+}
+
+int
 _token_list_equal_ignoring_space (token_list_t *a, token_list_t *b)
 {
 	token_node_t *node_a, *node_b;
 
+	if (a == NULL || b == NULL) {
+		int a_empty = _token_list_is_empty_ignoring_space(a);
+		int b_empty = _token_list_is_empty_ignoring_space(b);
+		return a_empty == b_empty;
+	}
+
 	node_a = a->head;
 	node_b = b->head;
 



More information about the mesa-commit mailing list