Fix overflow in fp_to_unsigned_bin_len length check. (#6075)

* Fix overflow in fp_to_unsigned_bin_len length check.
* Add a second check when i == a->used - 1.
This commit is contained in:
philljj
2023-02-10 10:46:37 -06:00
committed by GitHub
parent c2384674d8
commit 5b8fda1ac6

View File

@ -3834,7 +3834,10 @@ int fp_to_unsigned_bin_len(fp_int *a, unsigned char *b, int c)
for (; x >= 0; x--) { for (; x >= 0; x--) {
b[x] = 0; b[x] = 0;
} }
if ((i < a->used - 1) || ((a->dp[i] >> j) != 0)) { if (i < a->used - 1) {
return FP_VAL;
}
if ((i == a->used - 1) && ((a->dp[i] >> j) != 0)) {
return FP_VAL; return FP_VAL;
} }