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 <ian.d.romanick@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=97420
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Cc: mesa-stable@lists.freedesktop.org
Cc: Juan A. Suarez Romero <jasuarez@igalia.com>
Cc: Karol Herbst <karolherbst@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user