summaryrefslogtreecommitdiff
path: root/tests/glslparsertest/glslparsertest.c
diff options
context:
space:
mode:
authorPaul Berry <stereotype441@gmail.com>2013-02-06 12:56:42 -0800
committerPaul Berry <stereotype441@gmail.com>2013-02-27 12:58:46 -0800
commitfcd1d01b80600577e015c34dbd7b30a998d50560 (patch)
tree4bf6daf1929075e8a6fd770e7c3885c8113721d2 /tests/glslparsertest/glslparsertest.c
parent032acbd727f33232a16cc18fdd22dbf0c0e80ae3 (diff)
glslparsertest: Avoid uninitialized vars in parse_glsl_version_number.
Previously, if the user specified an ill-formed GLSL version number (or the implementation supplied an ill-formed number in its response to glGetString(GL_SHADING_LANGUAGE_VERSION)), glslparsertest would access uninitialized variables, resulting in unpredictable (and often confusing) behaviour. With this patch, glslparser test accepts version numbers either of the form "<int>" or "<int>.<int>". Ill-formed version numbers lead to a test failure. Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Chad Versace <chad.versace@linux.intel.com> Reviewed-by: Tom Gall <tom.gall@linaro.org> v2: Add comment explaining the use of sscanf(...) == 0.
Diffstat (limited to 'tests/glslparsertest/glslparsertest.c')
-rw-r--r--tests/glslparsertest/glslparsertest.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/tests/glslparsertest/glslparsertest.c b/tests/glslparsertest/glslparsertest.c
index 0903f68f1..cd5aa36e9 100644
--- a/tests/glslparsertest/glslparsertest.c
+++ b/tests/glslparsertest/glslparsertest.c
@@ -339,10 +339,18 @@ int process_options(int argc, char **argv)
static unsigned
parse_glsl_version_number(const char *str)
{
- unsigned major;
- unsigned minor;
+ unsigned major = 0;
+ unsigned minor = 0;
+
+ /* Accept a return value of either 1 or 2 from sscanf(), so
+ * that the version number may be supplied as either "<int>"
+ * or "<int>.<int>".
+ */
+ if (sscanf(str, "%u.%u", &major, &minor) == 0) {
+ printf("Ill-formed GLSL version number: %s\n", str);
+ piglit_report_result(PIGLIT_FAIL);
+ }
- sscanf(str, "%u.%u", &major, &minor);
return (major * 100) + minor;
}