x/upgrade/types, all: use of time.Time.IsZero() only works for zero value created variables, but will fail if from using time.Unix(0, 0); perhaps switch this check #8058
Labels
T:Bug
T: Security
Type: Code Hygiene
General cleanup and restructuring of code to provide clarity, flexibility, and modularity.
Milestone
Summary of Bug
TL;DR: Let's change the calls from
if time.Time.IsZero()
to beif time.Time.UnixNano() <= 0
to ensure that values obtained fromtime.Unix(zeroSecValue, zeroNsValue)
are caught too, otherwise the code isn't protected from such code usages and will incorrectly validate a plan that is incorrect. See https://play.golang.org/p/FV519_Nva0LThis code should not validate and should instead fail to execute this clearly invalid plan, but unfortunately it does
Description
The code in x/upgrade performs validation to ensure that either time or height are set as per
cosmos-sdk/x/upgrade/types/plan.go
Lines 43 to 51 in a51eac4
In Go, the way that we get time.Time.IsZero() to return true is if we retrieved time from:
var t time.Time
t, _ := time.Parse(INVALID_FORMAT)
time.Unix(SECONDS_SINCE_0001-01-01-00:00:00-to-1970, NANOSECONDS_SINCE_00-00-00-0000-to-1970)
and the usage of 2)
time.Parse
is properly well handledThe other way that this could happen is by
time.Unix
if mistakenly a zero value for minTime or an epoch value was zero, when used with
time.Unix
, we should instead useas per https://play.golang.org/p/FV519_Nva0L
and failing code
Version
Tip on master a51eac4
For Admin Use
The text was updated successfully, but these errors were encountered: