You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this case item->name is a std::string, file is a const char *.
The ternary's result type is std::string, so a temporary std::string is created from filename.
This goes out of scope before it is accessed from ShowErrorMessage on the next line.
While this particular one is trivial to fix, probably there are more like this in the codebase. I found it by chance when testing something else.
void SetDParamStr(uint n, const std::string &str) seems a somewhat problematic function signature in general as it can be difficult to avoid passing a temporary/rvalue.
Steps to reproduce
Use AddressSanitizer or some other heap checker, and trigger this code path using the NewGRF config window.
The text was updated successfully, but these errors were encountered:
JGRennison
added a commit
to JGRennison/Upstream-OpenTTD
that referenced
this issue
Nov 4, 2022
Version of OpenTTD
master
Expected result
No use after frees.
Actual result
SetDParamStr(0, StrEmpty(filename) ? item->name : filename);
at https://github.com/OpenTTD/OpenTTD/blob/master/src/settings.cpp#L1019In this case
item->name
is astd::string
,file
is aconst char *
.The ternary's result type is
std::string
, so a temporarystd::string
is created fromfilename
.This goes out of scope before it is accessed from
ShowErrorMessage
on the next line.While this particular one is trivial to fix, probably there are more like this in the codebase. I found it by chance when testing something else.
void SetDParamStr(uint n, const std::string &str)
seems a somewhat problematic function signature in general as it can be difficult to avoid passing a temporary/rvalue.Steps to reproduce
Use AddressSanitizer or some other heap checker, and trigger this code path using the NewGRF config window.
The text was updated successfully, but these errors were encountered: