From 5629332dcf9e3a7219af384b2b469289b3e4a325 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Thu, 1 May 2025 12:33:12 +0100 Subject: [PATCH] util: silence -Wstringop-overread in SHA1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In function ‘SHA1Update’, inlined from ‘SHA1Pad’ at ../../../../../../../mesa/src/util/sha1/sha1.c:157:2, inlined from ‘SHA1Final’ at ../../../../../../../mesa/src/util/sha1/sha1.c:168:2: ../../../../../../../mesa/src/util/sha1/sha1.c:135:25: warning: ‘SHA1Transform’ reading 64 bytes from a region of size 1 [-Wstringop-overread] 135 | SHA1Transform(context->state, (uint8_t *)&data[i]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../../../../../mesa/src/util/sha1/sha1.c:135:25: note: referencing argument 2 of type ‘const uint8_t[64]’ {aka ‘const unsigned char[64]’} ../../../../../../../mesa/src/util/sha1/sha1.c: In function ‘SHA1Final’: ../../../../../../../mesa/src/util/sha1/sha1.c:55:1: note: in a call to function ‘SHA1Transform’ 55 | SHA1Transform(uint32_t state[5], const uint8_t buffer[SHA1_BLOCK_LENGTH]) | ^~~~~~~~~~~~~ In function ‘SHA1Update’, inlined from ‘SHA1Pad’ at ../../../../../../../mesa/src/util/sha1/sha1.c:159:3, inlined from ‘SHA1Final’ at ../../../../../../../mesa/src/util/sha1/sha1.c:168:2: ../../../../../../../mesa/src/util/sha1/sha1.c:135:25: warning: ‘SHA1Transform’ reading 64 bytes from a region of size 1 [-Wstringop-overread] 135 | SHA1Transform(context->state, (uint8_t *)&data[i]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../../../../../mesa/src/util/sha1/sha1.c:135:25: note: referencing argument 2 of type ‘const uint8_t[64]’ {aka ‘const unsigned char[64]’} ../../../../../../../mesa/src/util/sha1/sha1.c: In function ‘SHA1Final’: ../../../../../../../mesa/src/util/sha1/sha1.c:55:1: note: in a call to function ‘SHA1Transform’ 55 | SHA1Transform(uint32_t state[5], const uint8_t buffer[SHA1_BLOCK_LENGTH]) | ^~~~~~~~~~~~~ In function ‘SHA1Update’, inlined from ‘SHA1Pad’ at ../../../../../../../mesa/src/util/sha1/sha1.c:160:2, inlined from ‘SHA1Final’ at ../../../../../../../mesa/src/util/sha1/sha1.c:168:2: ../../../../../../../mesa/src/util/sha1/sha1.c:135:25: warning: ‘SHA1Transform’ reading 64 bytes from a region of size 8 [-Wstringop-overread] 135 | SHA1Transform(context->state, (uint8_t *)&data[i]); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../../../../../mesa/src/util/sha1/sha1.c:135:25: note: referencing argument 2 of type ‘const uint8_t[64]’ {aka ‘const unsigned char[64]’} ../../../../../../../mesa/src/util/sha1/sha1.c: In function ‘SHA1Final’: ../../../../../../../mesa/src/util/sha1/sha1.c:55:1: note: in a call to function ‘SHA1Transform’ 55 | SHA1Transform(uint32_t state[5], const uint8_t buffer[SHA1_BLOCK_LENGTH]) | ^~~~~~~~~~~~~ Reaching this code is impossible for the SHA1Update() calls in SHA1Pad(). Use assume() to inform the compiler of this. Signed-off-by: Rhys Perry Reviewed-by: Mike Blumenkrantz Reviewed-by: Timur Kristóf Part-of: --- src/util/sha1/sha1.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/sha1/sha1.c b/src/util/sha1/sha1.c index de7514c70da..ed043fe39de 100644 --- a/src/util/sha1/sha1.c +++ b/src/util/sha1/sha1.c @@ -17,6 +17,7 @@ #include #include #include "u_endian.h" +#include "macros.h" #include "sha1.h" #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) @@ -131,8 +132,10 @@ SHA1Update(SHA1_CTX *context, const uint8_t *data, size_t len) if ((j + len) > 63) { (void)memcpy(&context->buffer[j], data, (i = 64-j)); SHA1Transform(context->state, context->buffer); - for ( ; i + 63 < len; i += 64) + for ( ; i + 63 < len; i += 64) { + assume(len >= 64); SHA1Transform(context->state, (uint8_t *)&data[i]); + } j = 0; } else { i = 0;