Skip to content

Commit

Permalink
runtime: guard against unsigned underflow in sleep time calculations
Browse files Browse the repository at this point in the history
Signed-off-by: Elias Naur <mail@eliasnaur.com>
  • Loading branch information
eliasnaur committed Apr 21, 2024
1 parent 1154212 commit 3b691fb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/runtime/scheduler.go
Expand Up @@ -202,10 +202,17 @@ func scheduler() {

var timeLeft timeUnit
if sleepQueue != nil {
timeLeft = timeUnit(sleepQueue.Data) - (now - sleepQueueBaseTime)
dt := (now - sleepQueueBaseTime)
timeLeft = timeUnit(sleepQueue.Data) - dt
if dt > timeUnit(sleepQueue.Data) {
timeLeft = 0
}
}
if timerQueue != nil {
timeLeftForTimer := timerQueue.whenTicks() - now
if now > timerQueue.whenTicks() {
timeLeftForTimer = 0
}
if sleepQueue == nil || timeLeftForTimer < timeLeft {
timeLeft = timeLeftForTimer
}
Expand Down

0 comments on commit 3b691fb

Please sign in to comment.