]> Cypherpunks.ru repositories - gostls13.git/commit
runtime, time: strictly enforce when, period constraints
authorMichael Pratt <mpratt@google.com>
Wed, 2 Dec 2020 17:19:13 +0000 (12:19 -0500)
committerMichael Pratt <mpratt@google.com>
Thu, 3 Dec 2020 21:23:16 +0000 (21:23 +0000)
commitb78b427be5e4c8a51a2b01b39c1ce6c4f39a93dc
treebba69775729b570a1b49020c7a398ec508d151aa
parentb635e4b808bf45ebd66e9f687e18b9af6bd634c1
runtime, time: strictly enforce when, period constraints

timer.when must always be positive. addtimer and modtimer already check
that it is non-negative; we expand it to include zero. Also upgrade from
pinning bad values to throwing, as these values shouldn't be possible to
pass (except as below).

timeSleep may overflow timer.nextwhen. This would previously have been
pinned by resetForSleep, now we fix it manually.

runOneTimer may overflow timer.when when adding timer.period. Detect
this and pin to maxWhen.

addtimer is now too strict to allow TestOverflowRuntimeTimer to test an
overflowed timer. Such a timer should not be possible; to help guard
against accidental inclusion siftup / siftdown will check timers as it
goes. This has been replaced with tests for period and sleep overflows.

Change-Id: I17f9739e27ebcb20d87945c635050316fb8e9226
Reviewed-on: https://go-review.googlesource.com/c/go/+/274853
Trust: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/time.go
src/time/internal_test.go
src/time/sleep.go
src/time/sleep_test.go