mirror of https://github.com/OpenTTD/OpenTTD
Fix 41b414b: Validate RAW_STRING parameter values in game_script mode
parent
47e12a8790
commit
43cea852a6
|
@ -799,6 +799,9 @@ uint ConvertDisplaySpeedToKmhishSpeed(uint speed)
|
||||||
{
|
{
|
||||||
return _units_velocity[_settings_game.locale.units_velocity].c.FromDisplay(speed * 16, true, 10);
|
return _units_velocity[_settings_game.locale.units_velocity].c.FromDisplay(speed * 16, true, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::vector<const char *> _game_script_raw_strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse most format codes within a string and write the result to a buffer.
|
* Parse most format codes within a string and write the result to a buffer.
|
||||||
* @param buff The buffer to write the final string to.
|
* @param buff The buffer to write the final string to.
|
||||||
|
@ -932,6 +935,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||||
|
|
||||||
sub_args_need_free[i] = true;
|
sub_args_need_free[i] = true;
|
||||||
sub_args.SetParam(i++, (uint64)(size_t)g);
|
sub_args.SetParam(i++, (uint64)(size_t)g);
|
||||||
|
_game_script_raw_strings.push_back(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* If we didn't error out, we can actually print the string. */
|
/* If we didn't error out, we can actually print the string. */
|
||||||
|
@ -941,7 +945,10 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 20; i++) {
|
for (i = 0; i < 20; i++) {
|
||||||
if (sub_args_need_free[i]) free((void *)sub_args.GetParam(i));
|
if (sub_args_need_free[i]) {
|
||||||
|
free((void *)sub_args.GetParam(i));
|
||||||
|
_game_script_raw_strings.pop_back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1046,6 +1053,10 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||||
|
|
||||||
case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
|
case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
|
||||||
const char *raw_string = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER);
|
const char *raw_string = (const char *)(size_t)args->GetInt64(SCC_RAW_STRING_POINTER);
|
||||||
|
if (game_script && std::find(_game_script_raw_strings.begin(), _game_script_raw_strings.end(), raw_string) == _game_script_raw_strings.end()) {
|
||||||
|
buff = strecat(buff, "(invalid RAW_STRING parameter)", last);
|
||||||
|
break;
|
||||||
|
}
|
||||||
buff = FormatString(buff, raw_string, args, last);
|
buff = FormatString(buff, raw_string, args, last);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue