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: don't use non-owning string pointer in StringParameter #11952

Merged
merged 1 commit into from Feb 2, 2024

Conversation

TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Feb 2, 2024

Motivation / Problem

Fixes #11922

The string pointer can become invalid before the reference is dropped, causing out-of-bound access in windows like ErrorWindow, or when closing the game.

Description

Instead of referencing a string, copy it. That way we know it is always safe.

Backported from JGRPP.

This is more a stop-gap solution, to remove the issue for upcoming release. Better solutions might be presented at a later stage.

Limitations

More memory usage when a pointer was used.

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 touches english.txt or translations? Check the guidelines
  • 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, game_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

The string pointer can become invalid before the reference is
dropped, causing out-of-bound access in windows like ErrorWindow,
or when closing the game.
@TrueBrain TrueBrain merged commit 59a046d into OpenTTD:master Feb 2, 2024
19 checks passed
@TrueBrain TrueBrain deleted the string-parameter-view branch February 2, 2024 22:01
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

Successfully merging this pull request may close these issues.

[Crash]: CopyDParam causes stack-buffer-overflow
3 participants