Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mixclient: Avoid jitter calculation panic #3448

Merged
merged 1 commit into from
Oct 15, 2024

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).

mixing/mixclient/client.go Outdated Show resolved Hide resolved
@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
2 checks passed
@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