mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-08-23 13:54:43 +02:00
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.
This commit is contained in:
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user