summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/glcpp/glcpp.h
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2016-11-08 11:06:05 -0800
committerIan Romanick <[email protected]>2016-11-10 10:57:59 -0800
commite85a747e294762785df2ce8a299c153254c6fca2 (patch)
tree336aa8c0062cde342d3b152955e5c3e8e97806f4 /src/compiler/glsl/glcpp/glcpp.h
parentcbba5e13acc2052349f7e2d304e6dddf31fb199a (diff)
glcpp: Handle '#version 0' and other invalid values
The #version directive can only handle decimal constants. Enforce that the value is a decimal constant. Section 3.3 (Preprocessor) of the GLSL 4.50 spec says: The language version a shader is written to is specified by #version number profile opt where number must be a version of the language, following the same convention as __VERSION__ above. The same section also says: __VERSION__ will substitute a decimal integer reflecting the version number of the OpenGL shading language. Use a separate flag to track whether or not the #version line has been encountered. Any possible sentinel (0 is currently used) could be specified in a #version directive. This would lead to trying to (internally) redefine __VERSION__. Since there is no parser location for this addition, NULL is passed. This eventually results in a NULL dereference and a segfault. Attempts to use -1 as the sentinel would also fail if '#version 4294967295' or '#version 18446744073709551615' were used. We should have piglit tests for both of these. Signed-off-by: Ian Romanick <[email protected]> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97420 Reviewed-by: Nicolai Hähnle <[email protected]> Cc: [email protected] Cc: Juan A. Suarez Romero <[email protected]> Cc: Karol Herbst <[email protected]>
Diffstat (limited to 'src/compiler/glsl/glcpp/glcpp.h')
-rw-r--r--src/compiler/glsl/glcpp/glcpp.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/compiler/glsl/glcpp/glcpp.h b/src/compiler/glsl/glcpp/glcpp.h
index bb4ad67f28b..232e053f46b 100644
--- a/src/compiler/glsl/glcpp/glcpp.h
+++ b/src/compiler/glsl/glcpp/glcpp.h
@@ -208,6 +208,15 @@ struct glcpp_parser {
void *state;
gl_api api;
unsigned version;
+
+ /**
+ * Has the #version been set?
+ *
+ * A separate flag is used because any possible sentinel value in
+ * \c ::version could also be set by a #version line.
+ */
+ bool version_set;
+
bool has_new_line_number;
int new_line_number;
bool has_new_source_number;