mixclient: Avoid jitter calculation panic#3448
Merged
davecgh merged 1 commit intodecred:masterfrom Oct 15, 2024
Merged
Conversation
davecgh
reviewed
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rand.Durationmay 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
sendBeforeis exactly equal tonow, then it will not be incremented by another epoch duration, leading to a potential invalidrand.Durationparameter. This is corrected by also checking for the times equaling exactly.Second,
time.Until()causes an additional call totime.Now(), which we have already fetched and all calculations must be based on it. IfsendBefore.Sub(now)is an extremely small value, it is possible thattime.Until(sendBefore)now returns a small negative or zero duration. This is corrected by replacing thetime.Untilcall withsendBefore.Sub(now).