Skip to content

Commit d4cf93c

Browse files
avoid overflow if clamping a digit with used size 0
1 parent c880fcf commit d4cf93c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

wolfssl/wolfcrypt/sp_int.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,11 @@ typedef struct sp_ecc_ctx {
695695
#define sp_clamp(a) \
696696
do { \
697697
int ii; \
698-
for (ii = (int)(a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
698+
if ((a)->used > 0) { \
699+
for (ii = (int)(a)->used - 1; ii >= 0 && (a)->dp[ii] == 0; ii--) { \
700+
} \
701+
(a)->used = (unsigned int)ii + 1; \
699702
} \
700-
(a)->used = (unsigned int)ii + 1; \
701703
} while (0)
702704

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

0 commit comments

Comments
 (0)