-
-
Notifications
You must be signed in to change notification settings - Fork 990
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 multi-account password saving #6290
Conversation
I tested the new code locally, it works both for single-account use case and for storing/loading multiple accounts |
I also hate to admit, but I cannot pinpoint where exactly the old code was broken. In my perception that was just messy code that is really hard to understand, with unneeded additional variable |
As discussed in #wesnoth-dev, it is indeed strange that it didn't expose the issue for multi-account credential saving for you in 1.14. But it does look like replacing manual It looks like only @CelticMinstrel has done any meaningful work on this code, so I'll suggest he review this before merging. |
UPD: When using this branch on an old corrupted |
To provide a bit of context for people who weren't today in IRC. Without this PR, for single-account credentials file, the entry in credentials file looks like: server: server.wesnoth.org:15000, login: vasili. For multi-account credentials file, without the PR, corrupted entries will be created upon save, such as: server: server.wesnoth.org:15000, login: login: vasili@server.wesnoth.org:15000=�����;sa��vasya2 (the login spans much further than it should, including the server and probably password of the previous/next entries) |
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.
Looks good, just one minor change to make.
src/preferences/credentials.cpp
Outdated
@@ -230,21 +233,15 @@ namespace preferences | |||
filesystem::delete_file(filesystem::get_credentials_file()); | |||
return; | |||
} | |||
secure_buffer credentials_data(1, CREDENTIAL_SEPARATOR); | |||
std::size_t offset = 1; | |||
secure_buffer credentials_data(0, CREDENTIAL_SEPARATOR); |
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.
(0, CREDENTIAL_SEPARATOR)
does nothing - just remove it.
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.
Thanks for the review! Addressed the comment
Fixes GH-6288, and hopefully makes the code more readable / easier to understand.
ed58d05
to
701bb5a
Compare
The only potential bug I see in the old code is that the second resize (for the difference in size between escaped and non-escaped keys) doesn't pad the buffer with CREDENTIAL_SEPARATOR. The new code looks like a definite improvement. It might be a bit slower due to not pre-allocating the buffer, but this is hardly a performance-critical path. |
@AI0867 totally agree. Also, for this code path, I'd indeed prefer readability, maintainability and less bugs, over performance optimization %insert-donald-knuth-quote-here% |
Mostly unrelated, but I'm unsure if I should open a new issue for this: I noticed a TODO to do key stretching on the autogenerated key. This seems like a good idea, but unfortunately, it comes with a whole host of backwards-compatibility issues, especially if we want to be able to allow older versions of wesnoth to keep using the same credentials file. Should we open a new issue for that to think about what a good design would even look like? |
@AI0867 I don't know, I can't really say. Normally I always try to prioritize fixing bugs, and only then doing new features. But that is subjective of course. |
Fixes GH-6288, and hopefully makes the code
more readable / easier to understand.