Validate RAW_STRING parameter values in game_script mode
This commit is contained in:
@@ -1050,6 +1050,8 @@ uint ConvertDisplayQuantityToCargoQuantity(CargoID cargo, uint quantity)
|
||||
return quantity;
|
||||
}
|
||||
|
||||
static std::vector<const char *> _game_script_raw_strings;
|
||||
|
||||
/**
|
||||
* Parse most format codes within a string and write the result to a buffer.
|
||||
* @param buff The buffer to write the final string to.
|
||||
@@ -1183,6 +1185,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
|
||||
sub_args_need_free[i] = true;
|
||||
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. */
|
||||
@@ -1192,7 +1195,10 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
}
|
||||
|
||||
for (int 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;
|
||||
}
|
||||
@@ -1297,6 +1303,10 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
|
||||
|
||||
case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user