Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit 0513b8a

Browse files
committed
Protect from underflow in timer::read
The timer may be read when it is past its timeout, but it has not been timed-out by the scheduler. Without this, an underflow would occur. `0` is returned on underflow because that is what Erlang returns.
1 parent 03ce798 commit 0513b8a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lumen_runtime/src/timer.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,16 @@ impl Hierarchy {
133133
.get(&timer_reference_number)
134134
.and_then(|weak_timer| weak_timer.upgrade())
135135
.map(|rc_timer| {
136-
rc_timer.monotonic_time_milliseconds - monotonic::time_in_milliseconds()
136+
// The timer may be read when it is past its timeout, but it has not been timed-out
137+
// by the scheduler. Without this, an underflow would occur.
138+
// `0` is returned on underflow because that is what Erlang returns.
139+
match rc_timer
140+
.monotonic_time_milliseconds
141+
.checked_sub(monotonic::time_in_milliseconds())
142+
{
143+
Some(difference) => difference,
144+
None => 0,
145+
}
137146
})
138147
}
139148

0 commit comments

Comments
 (0)