Skip to content

Commit

Permalink
avoid overflow if clamping a digit with used size 0
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Jul 5, 2024
1 parent c880fcf commit d4cf93c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions wolfssl/wolfcrypt/sp_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -695,9 +695,11 @@ typedef struct sp_ecc_ctx {
#define sp_clamp(a) \
do { \
int ii; \
for (ii = (int)(a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
if ((a)->used > 0) { \
for (ii = (int)(a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
} \
(a)->used = (unsigned int)ii + 1; \
} \
(a)->used = (unsigned int)ii + 1; \
} while (0)

/* Check the compiled and linked math implementation are the same.
Expand Down

0 comments on commit d4cf93c

Please sign in to comment.