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 <pendingchaos02@gmail.com>
Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34785>
This local copy of a SHA1 implementation based on the sources below.
Why:
- Some libraries suffer from race condition and other issues. For example see
commit ade3108bb5b0 ("util: Fix race condition on libgcrypt initialization").
- Fold the handling and detection of _eight_ implementations at configure
stage and _seven_ different codepaths.
- Have a single, uniform, code used by developers, testers and users.
- Avoid conflicts when using software which ships with it's own SHA1 library.
The latter of which conflicting with the one mesa is build against.
Source:
The SHA1 implementation is copied verbatim from the following links.
At the time of checkout HEAD is 1.25 and 1.24 respectively.
http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/lib/libc/hash/sha1.c?rev=HEAD
http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/include/sha1.h?rev=HEAD
Notes:
- The files should not have any local changes. If there are any they should be
clearly documented below and one should aim to upstream them where possible.
- Files will be periodically syncronised with the respective upstream sources.
Updates will be made regularly, but since the code is _not_ aimed as a
cryptography solution any issues found should not be considered security ones.
Local changes:
- Removed __bounded__ attribute qualifiers. Unavailable on platforms targeted
by Mesa. Upstream status: TBD (N/A ?)
- Pick the sha1.h header from the current folder, by using "" over <> in the
include directive. Upstream status: TBD
- Remove unused function prototypes - SHA1End, SHA1File, SHA1FileChunk and
SHA1Data. Upstream status: TBD
- Use stdint.h integer types - u_int{8,16,32}_t -> uint{8,16,32}_t and
u_int -> uint32_t, change header include. Upstream status: TBD
- Revert sha1.c rev 1.26 change (introduce DEF_WEAK).
Upstream status: TBD (N/A ?)
- Add stdint.h include in sha1.h for uint*_t types. Upstream status: TBD
- Add stddef.h include in sha1.h for size_t type. Upstream status: TBD
- Use memset over explicit_bzero, since memset_s once isn't widely available.
Upstream status: TBD (N/A ?)
- Manually expand __BEGIN_DECLS/__END_DECLS and make sure that they include
the struct declaration.
Upstream status: TBD
- Add non-typedef struct name.
Upstream status: TBD