From 03e40fdc259fedfa4912552cea7e9a312e669c0d Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Fri, 31 Jul 2026 15:21:28 +0200 Subject: [PATCH] coding: remove unreachable out operand in the Base64 decoders Premise: coding.c:177 (Base64_Decode_nonCT) and coding.c:298 (Base64_Decode) both open with if ((in == NULL && inLen > 0) || out == NULL || outLen == NULL) return BAD_FUNC_ARG; which establishes out != NULL for the rest of each function. Claim: coding.c:281 and coding.c:395, `if (out && *outLen > i)` -- the `out` operand in both. Proof: out is a parameter and is never reassigned in either function; the only uses between the entry check and the null-terminator write are subscripted stores (out[i]). Reaching :281 / :395 therefore implies out != NULL, so the operand is invariantly true and its independence pair is unreachable. Scope: neither function contains an #if/#ifdef in the span. Base64_Decode_nonCT is compiled under !BASE64_NO_TABLE and aliased to Base64_Decode under BASE64_NO_TABLE (:404-408); both variants carry the same entry check, so the argument holds either way. Evidence: llvm-cov MC/DC records both conditions' pairs as uncovered (reports/coding/GAPS.md rows 281:9:281:27:0 and 395:9:395:27:0). Deliberately untouched: the textually identical line in DoBase64_Encode (coding.c:608). There out == NULL is the documented size-query mode (`getSzOnly = (out == NULL)` at :520, returning LENGTH_ONLY_E), so that operand is live and load-bearing -- base64_test exercises it. Compiler cross-check: gcc -O2 emits byte-identical code for this file before and after this commit -- the optimiser had already folded the removed condition, independently confirming it was dead. --- wolfcrypt/src/coding.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/coding.c b/wolfcrypt/src/coding.c index e9b70edae4..e2b1afe2c9 100644 --- a/wolfcrypt/src/coding.c +++ b/wolfcrypt/src/coding.c @@ -278,7 +278,7 @@ int Base64_Decode_nonCT(const byte* in, word32 inLen, byte* out, word32* outLen) } /* If the output buffer has a room for an extra byte, add a null terminator */ - if (out && *outLen > i) + if (*outLen > i) out[i]= '\0'; /* Note, *outLen won't reflect the optional terminating null. */ @@ -392,7 +392,7 @@ int Base64_Decode(const byte* in, word32 inLen, byte* out, word32* outLen) } /* If the output buffer has a room for an extra byte, add a null terminator */ - if (out && *outLen > i) + if (*outLen > i) out[i]= '\0'; /* Note, *outLen won't reflect the optional terminating null. */