-
Notifications
You must be signed in to change notification settings - Fork 384
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
Fix off-by-one error when choosing access method candidates #5811
Fix off-by-one error when choosing access method candidates #5811
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @MarkusPettersson98)
mullvad-daemon/src/api.rs
line 250 at r1 (raw file):
// by starting from the back of the available access methods we // effectively look for candidates starting from index 0. access_method_settings.cardinality() - 1,
Correct me if I'm wrong, but this seems to end up selecting the last method in the list if a method should be added before get_next
is called.
I think a less clever solution might be better. Maybe by not setting an initial method at all, or not relying on get_next
to select the "first" method.
But we could use this as a hotfix if we need one.
cc45d53
to
cd31aed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 9 files reviewed, 1 unresolved discussion (waiting on @dlon)
mullvad-daemon/src/api.rs
line 250 at r1 (raw file):
Previously, dlon (David Lönnhager) wrote…
Correct me if I'm wrong, but this seems to end up selecting the last method in the list if a method should be added before
get_next
is called.I think a less clever solution might be better. Maybe by not setting an initial method at all, or not relying on
get_next
to select the "first" method.But we could use this as a hotfix if we need one.
Turns out that the solution in this module was very straightforward - the turned out to be somewhere else! See my updated PR comment for context 😊
Refactored get_next_inner
(now select_next_active
) to be more declarative and start looking for candidates starting from the start
position, otherwise not much else has changed here.
92f065f
to
30cad4d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 11 of 11 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved
8275764
to
74340a6
Compare
74340a6
to
b226b8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status:complete! all files reviewed, all discussions resolved
As the code comment says:
get_next_inner
will skip thestart
position, which means that by starting from the back of the available access methods we effectively look for candidates starting from index 0, i.e. the position of thedirect
access method. It's probably a good idea to not default users to bridges/proxies to reach the API.Edit: The solution was found elsewhere. As it turns out,
mullvad-api
always forced a rotation of access methods wheneverMullvadRestHandle
was initialized, which means thatget_next_inner
/select_next_active
was called twice at startup. This was subsequently solved by passing along an initial access method to the constructor ofMullvadRestHandle
, as is done with the tunnel state machine.This change is