Skip to content

Commit b358454

Browse files
committed
f Error on checked add
The only way we could overflow here is if we actually read an update at u64::MAX, and that is no longer allowed to happen, so this is an error.
1 parent 6afa4ad commit b358454

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lightning/src/util/persist.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,10 @@ where
413413
// ...parse and apply the updates with an id higher than the monitor.
414414
let mut current_update_id = monitor.get_latest_update_id();
415415
loop {
416-
current_update_id = match current_update_id.checked_add(1) {
417-
Some(next_update_id) => next_update_id,
418-
None => break,
419-
};
416+
current_update_id = current_update_id.checked_add(1).ok_or(io::Error::new(
417+
io::ErrorKind::Other,
418+
"invalid update found at u64::MAX",
419+
))?;
420420
let update_name = UpdateName::from(current_update_id);
421421
let update = match self.read_monitor_update(&monitor_name, &update_name) {
422422
Ok(update) => update,
@@ -619,7 +619,7 @@ where
619619
let mut end = monitor.get_latest_update_id();
620620
// Typically, we'll clean up between the last two known full monitors. We
621621
// shouldn't bother cleaning up if the update_id difference is less than or
622-
// equal to one, since that implies no updates would be there.
622+
// equal to one, since that implies no updates would be there.
623623
if end - start > 1 {
624624
if monitor.get_latest_update_id() == CLOSED_CHANNEL_UPDATE_ID {
625625
// We don't want to clean the rest of u64, so just do possible pending updates

0 commit comments

Comments
 (0)