glsl: fix glsl_struct_field size calculations for shader cache
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Thu, 24 Aug 2017 13:41:08 +0000 (15:41 +0200)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Fri, 25 Aug 2017 07:05:28 +0000 (09:05 +0200)
commit4da6cf6c98aeca8c143ecb5e0ada5e1eee81a0f5
treef686bb7a1c5420e41f3aa1b75be74001498ae601
parentf623e1742f20cffe2c91287ab6b0b0a39a78e02c
glsl: fix glsl_struct_field size calculations for shader cache

Found by address sanitizer:

==22621==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61400000cbd8 at pc 0x7f561610a4ff bp 0x7ffca85f9d50 sp 0x7ffca85f94f8
READ of size 344 at 0x61400000cbd8 thread T0
    #0 0x7f561610a4fe  (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x5f4fe)
    #1 0x7f560bb305a5 in memcpy /usr/include/x86_64-linux-gnu/bits/string3.h:53
    #2 0x7f560bb305a5 in blob_write_bytes ../../../mesa-src/src/compiler/glsl/blob.c:136
    #3 0x7f560be7d7ff in encode_type_to_blob ../../../mesa-src/src/compiler/glsl/shader_cache.cpp:153
    #4 0x7f560be81222 in write_program_resource_data ../../../mesa-src/src/compiler/glsl/shader_cache.cpp:950
    #5 0x7f560be81222 in write_program_resource_list ../../../mesa-src/src/compiler/glsl/shader_cache.cpp:1118
    #6 0x7f560be81222 in shader_cache_write_program_metadata(gl_context*, gl_shader_program*) ../../../mesa-src/src/compiler/glsl/shader_cache.cpp:1407
    #7 0x7f560b825fdb in link_program ../../../mesa-src/src/mesa/main/shaderapi.c:1163

Fixes: 073a84ff60db ("glsl: stop adding pointers from glsl_struct_field to the cache")
Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/compiler/glsl/shader_cache.cpp