Commit 1d5bda32ce for openssl.org
commit 1d5bda32ce1e3f437305b313b3d9c3b761e0ce81
Author: Richard Levitte <levitte@openssl.foundation>
Date: Tue Nov 17 09:11:32 2026 +0100
providers/.../digests/kt_prov.c: make kt_length_encode() bound explicit
Building with -O3 -march=x86-64-v3 --strict-warnings fails in this
file: gcc's -Wstringop-overflow claims kt_length_encode() can write
16 bytes into the callers' 9-byte enc[] array.
The claim is spurious—the byte count never exceeds sizeof(size_t),
so at most 9 bytes are written—but the bound only exists implicitly
in the loop structure, which gcc's range analysis does not see through
in that configuration. This matters in practice: GitHub runners Ubuntu
26.04 image uses the amd64v3 architecture variant[1], with x86-64-v3
being the default target microarchitecture level for gcc there.
Make the bound explicit in the loop condition, serving both
the reader and the compiler's warning analysis.
[1] https://ubuntu.com/cloud/public-cloud/docs/all-clouds-explanation/architecture-variants/
Fixes: c3d7ab550010 ("Add support for RFC 9861 TurboSHAKE and KangarooTwelve XOF digests")
Assisted-by: Pi:moonshotai/kimi-k3
Signed-off-by: Richard Levitte <levitte@openssl.foundation>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Merge-date: Wed Nov 18 06:24:05 2026
Merged-from: https://github.com/openssl/openssl/pull/33789
diff --git a/providers/implementations/digests/kt_prov.c b/providers/implementations/digests/kt_prov.c
index b8566a9318..a515b07786 100644
--- a/providers/implementations/digests/kt_prov.c
+++ b/providers/implementations/digests/kt_prov.c
@@ -64,7 +64,12 @@ static size_t kt_length_encode(size_t x, unsigned char *out)
{
size_t n = 0, t = x, i;
- while (t > 0) {
+ /*
+ * The n < sizeof(t) bound is provably never reached (t >>= 8 reaches
+ * zero in at most sizeof(t) steps), but it makes the maximum value of
+ * n visible to the reader and to compiler warning analysis.
+ */
+ while (t > 0 && n < sizeof(t)) {
n++;
t >>= 8;
}