]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
EAP-pwd: Make code easier for static analyzers
authorJouni Malinen <j@w1.fi>
Sun, 9 Feb 2025 16:20:31 +0000 (18:20 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 9 Feb 2025 17:08:30 +0000 (19:08 +0200)
resultbytelen cannot be 0 when resultbitlen != 0 and as such,
result[resultbytelen - 1] here cannot point to invalid index. However,
this is apparently too complex for static analyzers, so make this more
obvious to avoid false positives.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/eap_common/eap_pwd_common.c

index ff8ad8d72a9ddcc887f3c8cd90ed36240e9286c8..fa7ecd01e443d5f6106b6b92d208ec1b57007aa8 100644 (file)
@@ -76,7 +76,7 @@ static int eap_pwd_kdf(const u8 *key, size_t keylen, const u8 *label,
        }
 
        /* since we're expanding to a bit length, mask off the excess */
-       if (resultbitlen % 8) {
+       if (resultbytelen > 0 && (resultbitlen % 8)) {
                u8 mask = 0xff;
                mask <<= (8 - (resultbitlen % 8));
                result[resultbytelen - 1] &= mask;