Mesa (10.3): glcpp: Don' t use alternation in the lookahead for empty pragmas.

Emil Velikov evelikov at kemper.freedesktop.org
Mon Aug 25 21:33:43 UTC 2014


Module: Mesa
Branch: 10.3
Commit: 627d31dc36be6a92775b038bc4a26a96df8e7191
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=627d31dc36be6a92775b038bc4a26a96df8e7191

Author: Carl Worth <cworth at cworth.org>
Date:   Mon Aug 18 11:36:12 2014 -0700

glcpp: Don't use alternation in the lookahead for empty pragmas.

We've found that there's a buffer overrun bug in flex that's triggered by
using alternation in a lookahead pattern.

Fortunately, we don't need to match the exact {NEWLINE} expression to
detect an empty pragma. It suffices to verify that there are no non-space
characters before any newline character. So we can use a simple [\r\n] to
get the desired behavior while avoiding the flex bug.

Fixes the regression of piglit's 17000-consecutive-chars-identifier test,
(which has been crashing since commit
04e40fd337a244ee77ef9553985e9398ff0344af ).

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=82472
Signed-off-by: Carl Worth <cworth at cworth.org>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

CC: <mesa-stable at lists.freedesktop.org>
(cherry picked from commit 23163df24cf96107ee8ccb372db20f49e9d88948)

---

 src/glsl/glcpp/glcpp-lex.l |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
index 98d500e..fa9aa50 100644
--- a/src/glsl/glcpp/glcpp-lex.l
+++ b/src/glsl/glcpp/glcpp-lex.l
@@ -289,8 +289,14 @@ HEXADECIMAL_INTEGER	0[xX][0-9a-fA-F]+[uU]?
 }
 
 	/* Swallow empty #pragma directives, (to avoid confusing the
-	 * downstream compiler). */
-<HASH>pragma{HSPACE}*/{NEWLINE} {
+	 * downstream compiler).
+	 *
+	 * Note: We use a simple regular expression for the lookahead
+	 * here. Specifically, we cannot use the complete {NEWLINE} expression
+	 * since it uses alternation and we've found that there's a flex bug
+	 * where using alternation in the lookahead portion of a pattern
+	 * triggers a buffer overrun. */
+<HASH>pragma{HSPACE}*/[\r\n] {
 	BEGIN INITIAL;
 }
 




More information about the mesa-commit mailing list