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 #7998: Crash when scripts tried to access companies with invalid IDs. #8010

Merged
merged 1 commit into from Feb 22, 2020

Conversation

frosch123
Copy link
Member

ResolveCompany reported ID 256 as valid, if ID 0 is valid, etc...

Actually, all casts are wrong in that file. Company::Get and Company::IsValidID both accept a size_t, so it is best to never cast anything, so there is always only one conversion from ScriptCompany::CompanyID to size_t.

@frosch123 frosch123 added the backport requested This PR should be backport to current release (RC / stable) label Feb 18, 2020
@LordAro
Copy link
Member

LordAro commented Feb 18, 2020

Also should update ScriptCompany::CompanyID to match ::CompanyID definition (with byte type). For consistency if nothing else

@frosch123
Copy link
Member Author

frosch123 commented Feb 18, 2020

I have no idea how much that would break.
Spectators use 0xFF as ID, probably deity as well. So it's reasonable that the script API uses some other constant for real invalid.

Feel free to change that in master, but I would recommend against backporting such a change.

Copy link
Contributor

@glx22 glx22 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.

BTW while reading the file I noticed a weird thing, GetName() returns nullptr for invalid company, while GetPresidentName() returns an empty string. but clearly not related to this PR :)

@LordAro LordAro merged commit 0ade8b2 into OpenTTD:master Feb 22, 2020
@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 Mar 31, 2020
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