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

[Bug]: SDTG_MMANY/ManyOfMany settings may write unintiailised bytes into the config file when no bits are set #9766

Closed
JGRennison opened this issue Dec 23, 2021 · 0 comments

Comments

@JGRennison
Copy link
Contributor

Version of OpenTTD

master

Expected result

Config file is correct (zero length string value) when a SDTG_MMANY/ManyOfMany setting has no bits set.

Actual result

Uninitialised bytes may be written into the config file when a SDTG_MMANY/ManyOfMany setting has no bits set.
Clearing all bits of display_opt may result in the config file line for display_opt having uninitialised bytes written for the value.
This may cause an error at config load time, and/or make the config file invalid UTF-8, etc.

ManyOfManySettingDesc::FormatValue does not write any bytes if there are no bits set, and the output buffer is not initialised, and therefore not zero-terminated after FormatValue is called.
(StringSettingDesc::FormatValue has extra code to handle this special case).

See also: JGRennison/OpenTTD-patches#344

Steps to reproduce

  1. Clear all bits of display_opt in the usual way.
  2. Exit OpenTTD to write config.
  3. Open OpenTTD and exit to write config again if necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant