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

Fix: [Network] Reading beyond the length of the server's ID when hashing passwords #9176

Merged
merged 1 commit into from May 2, 2021

Conversation

rubidium42
Copy link
Contributor

Motivation / Problem

Under normal circumstances the server's ID is 32 characters excluding '\0', however this can be changed at the server. This ID is sent to the server for company name hashing. The client reads it into a statically allocated buffer of 33 bytes, but fills only the bytes it received from the server. However, the hash assumes all 33 bytes are set, thus potentially reading uninitialized data, or a part of the server ID of a previous game in the hashing routine.
It is still reading from memory assigned to the server ID, so nothing bad happens, except that company passwords might not work correctly.

Description

Get the length of the network/server ID string when hashing, and interpret anything after that length as '\0'.
Kept the result of the hashing the same, except when the overread would occur.

Limitations

Xor-ing for salting is not a common practice anymore, usually strings are just appended after each other. I chose not to break those for now as that could break (custom) servers that save the company passwords locally, so it would be better to change the hashing logic when there is a way to denote versions/types of hashes.
Using std::string would make some things easier/nicer, but to be able to backport this I have done the minimal amount. I have a branch where it does convert it to std::string, but that requires many related commits so not suitable for a backport.

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

…ing password

Under normal circumstances the server's ID is 32 characters excluding '\0', however this can be changed at the server. This ID is sent to the server for company name hashing. The client reads it into a statically allocated buffer of 33 bytes, but fills only the bytes it received from the server. However, the hash assumes all 33 bytes are set, thus potentially reading uninitialized data, or a part of the server ID of a previous game in the hashing routine.
It is still reading from memory assigned to the server ID, so nothing bad happens, except that company passwords might not work correctly.
@rubidium42 rubidium42 added the backport requested This PR should be backport to current release (RC / stable) label May 2, 2021
@rubidium42 rubidium42 merged commit 56aa6d0 into OpenTTD:master May 2, 2021
@rubidium42 rubidium42 deleted the fix_server_id_overread branch May 2, 2021 09:51
@LordAro LordAro added backported This PR is backported to a current release (RC / stable) and removed backport requested This PR should be backport to current release (RC / stable) labels May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported This PR is backported to a current release (RC / stable)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants