OSDN Git Service

glsl: rewrite glsl_type::record_key_hash() to avoid buffer overflow
authorBrian Paul <brianp@vmware.com>
Thu, 16 Apr 2015 21:29:18 +0000 (15:29 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 22 Apr 2015 14:58:05 +0000 (08:58 -0600)
commit31667e6237d30188d0b29e17f5b9892f10c0d83a
treeb38ae8b06be273ad3f9bff5ace9d9dbb3c22073f
parentbd4dbdfa519362f74263a2c277a3b4be841acd06
glsl: rewrite glsl_type::record_key_hash() to avoid buffer overflow

This should be more efficient than the previous snprintf() solution.
But more importantly, it avoids a buffer overflow bug that could result
in crashes or unpredictable results when processing very large interface
blocks.

For the app in question, key->length = 103 for some interfaces.  The check
if size >= sizeof(hash_key) was insufficient to prevent overflows of the
hash_key[128] array because it didn't account for the terminating zero.
In this case, this caused the call to hash_table_string_hash() to return
different results for identical inputs, and then shader linking failed.

This new solution also takes all structure fields into account instead
of just the first 15 when sizeof(pointer)==8.

Cc: mesa-stable@lists.freedesktop.org
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/glsl_types.cpp