Fix: [Script] Improve ScriptText validation (#11721)

The validation is now done in two steps:
 - First we get the list of parameters in the same order they used to be in encoded string
 - Then we validate the parameter types like FormatString would use them while encoding the string
This commit is contained in:
Loïc Guilloux
2024-01-18 18:06:30 +01:00
committed by GitHub
parent 28ef5146ba
commit bf4b669628
4 changed files with 87 additions and 60 deletions

View File

@@ -130,11 +130,31 @@ public:
private:
using ScriptTextRef = ScriptObjectRef<ScriptText>;
using StringIDList = std::vector<StringID>;
using Param = std::variant<SQInteger, std::string, ScriptTextRef>;
struct ParamCheck {
StringID owner;
int idx;
Param *param;
ParamCheck(StringID owner, int idx, Param *param) : owner(owner), idx(idx), param(param) {}
};
using ParamList = std::vector<ParamCheck>;
using ParamSpan = std::span<ParamCheck>;
StringID string;
std::variant<SQInteger, std::string, ScriptTextRef> param[SCRIPT_TEXT_MAX_PARAMETERS];
Param param[SCRIPT_TEXT_MAX_PARAMETERS];
int paramc;
/**
* Internal function to recursively fill a list of parameters.
* The parameters are added as _GetEncodedText used to encode them
* before the addition of parameter validation.
* @param params The list of parameters to fill.
*/
void _FillParamList(ParamList &params);
/**
* Internal function for recursive calling this function over multiple
* instances, while writing in the same buffer.
@@ -142,7 +162,7 @@ private:
* @param param_count The number of parameters that are in the string.
* @param seen_ids The list of seen StringID.
*/
void _GetEncodedText(std::back_insert_iterator<std::string> &output, int &param_count, StringIDList &seen_ids);
void _GetEncodedText(std::back_insert_iterator<std::string> &output, int &param_count, StringIDList &seen_ids, ParamSpan args);
/**
* Set a parameter, where the value is the first item on the stack.