Skip to content

Commit 4bb4648

Browse files
Ensure lru_count does not overflow.
1 parent f94489b commit 4bb4648

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13214,7 +13214,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
1321413214
err = add_entry(idx1, A);
1321513215
}
1321613216
}
13217-
if (err == MP_OKAY && idx1 != -1) {
13217+
if (err == MP_OKAY && idx1 != -1 && fp_cache[idx1].lru_count < (INT_MAX-1)) {
1321813218
/* increment LRU */
1321913219
++(fp_cache[idx1].lru_count);
1322013220
}
@@ -13231,7 +13231,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
1323113231
}
1323213232
}
1323313233

13234-
if (err == MP_OKAY && idx2 != -1) {
13234+
if (err == MP_OKAY && idx2 != -1 && fp_cache[idx2].lru_count < (INT_MAX-1)) {
1323513235
/* increment LRU */
1323613236
++(fp_cache[idx2].lru_count);
1323713237
}
@@ -13368,7 +13368,7 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
1336813368
if (idx >= 0)
1336913369
err = add_entry(idx, G);
1337013370
}
13371-
if (err == MP_OKAY && idx >= 0) {
13371+
if (err == MP_OKAY && idx >= 0 && fp_cache[idx].lru_count < (INT_MAX-1)) {
1337213372
/* increment LRU */
1337313373
++(fp_cache[idx].lru_count);
1337413374
}
@@ -13539,7 +13539,7 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
1353913539
if (idx >= 0)
1354013540
err = add_entry(idx, G);
1354113541
}
13542-
if (err == MP_OKAY && idx >= 0) {
13542+
if (err == MP_OKAY && idx >= 0 && fp_cache[idx].lru_count < (INT_MAX-1)) {
1354313543
/* increment LRU */
1354413544
++(fp_cache[idx].lru_count);
1354513545
}

0 commit comments

Comments
 (0)