Skip to content

mixclient: Avoid jitter calculation panic#3448

Merged
davecgh merged 1 commit intodecred:masterfrom
jrick:duration_panic
Oct 15, 2024
Merged

mixclient: Avoid jitter calculation panic#3448
davecgh merged 1 commit intodecred:masterfrom
jrick:duration_panic

Conversation

@jrick
Copy link
Member

@jrick jrick commented Oct 15, 2024

rand.Duration may not be called with a negative or zero upper bound, but this was seen to occur in (*Client).prDelay(). Two notable possible bugs stood out.

First, if sendBefore is exactly equal to now, then it will not be incremented by another epoch duration, leading to a potential invalid rand.Duration parameter. This is corrected by also checking for the times equaling exactly.

Second, time.Until() causes an additional call to time.Now(), which we have already fetched and all calculations must be based on it. If sendBefore.Sub(now) is an extremely small value, it is possible that time.Until(sendBefore) now returns a small negative or zero duration. This is corrected by replacing the time.Until call with sendBefore.Sub(now).

@davecgh davecgh added this to the 2.1.0 milestone Oct 15, 2024
Copy link
Member

@davecgh davecgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good after squash.

rand.Duration may not be called with a negative or zero upper bound, but this
was seen to occur in (*Client).prDelay().  Two notable possible bugs stood out.

First, if sendBefore is exactly equal to now, then it will not be incremented
by another epoch duration, leading to a potential invalid rand.Duration
parameter.  This is corrected by also checking for the times equaling exactly.

Second, time.Until() causes an additional call to time.Now(), which we have
already fetched and all calculations must be based on it.  If
sendBefore.Sub(now) is an extremely small value, it is possible that
time.Until(sendBefore) now returns a small negative or zero duration.  This is
corrected by replacing the time.Until call with sendBefore.Sub(now).
@davecgh davecgh merged commit 10a2845 into decred:master Oct 15, 2024
@jrick jrick deleted the duration_panic branch October 15, 2024 16:09
@davecgh davecgh modified the milestones: 2.1.0, 2.0.5 Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants