Fix Coverity 1498612: integer overflow
authorPauli <pauli@openssl.org>
Wed, 16 Mar 2022 03:13:25 +0000 (14:13 +1100)
committerPauli <pauli@openssl.org>
Fri, 25 Mar 2022 06:31:37 +0000 (17:31 +1100)
The assert added cannot ever fail because (current & 0xFFFF) != 0 from the
while loop and the trailing zero bit count therefore cannot be as large as 32.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/17892)

crypto/ec/curve448/curve448.c

index 9b9786da8fe7577251e4d9591ae33d8195ca4305..4db72cd28d9c5d3edac2e34d210da5a533f784f4 100644 (file)
@@ -586,6 +586,7 @@ static int recode_wnaf(struct smvt_control *control,
             int32_t delta = odd & mask;
 
             assert(position >= 0);
+            assert(pos < 32);       /* can't fail since current & 0xFFFF != 0 */
             if (odd & (1 << (table_bits + 1)))
                 delta -= (1 << (table_bits + 1));
             current -= delta * (1 << pos);