radv: don't pass null to _mesa_sha1_update
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 5 Aug 2020 20:03:22 +0000 (21:03 +0100)
committerMarge Bot <eric+marge@anholt.net>
Thu, 20 Aug 2020 10:52:19 +0000 (10:52 +0000)
This could then pass NULL to memcpy. Fixes UBSan error:
../src/util/sha1/sha1.c:140:8: runtime error: null pointer passed as argument 2, which is declared to never be null

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6206>

src/amd/vulkan/radv_pipeline_cache.c

index 8cbf312019ca183db5a2022b8b8dd448bb5a8988..fe38f3010094b96ae67f4d2842bda29f4c088d9a 100644 (file)
@@ -133,7 +133,7 @@ radv_hash_shaders(unsigned char *hash,
 
                        _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
                        _mesa_sha1_update(&ctx, stages[i]->pName, strlen(stages[i]->pName));
 
                        _mesa_sha1_update(&ctx, module->sha1, sizeof(module->sha1));
                        _mesa_sha1_update(&ctx, stages[i]->pName, strlen(stages[i]->pName));
-                       if (spec_info) {
+                       if (spec_info && spec_info->mapEntryCount) {
                                _mesa_sha1_update(&ctx, spec_info->pMapEntries,
                                                  spec_info->mapEntryCount * sizeof spec_info->pMapEntries[0]);
                                _mesa_sha1_update(&ctx, spec_info->pData, spec_info->dataSize);
                                _mesa_sha1_update(&ctx, spec_info->pMapEntries,
                                                  spec_info->mapEntryCount * sizeof spec_info->pMapEntries[0]);
                                _mesa_sha1_update(&ctx, spec_info->pData, spec_info->dataSize);