diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-11-12 08:36:26 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2018-11-12 08:36:26 -0300 |
commit | baa8678d2a8b4564b984d869e737f94f5720ff54 (patch) | |
tree | 922acff7aff4e794acc6d22c9ecca41b2233d878 /servers/visual | |
parent | 4a0f7837324801f405e5c87619219b8cd03c86c2 (diff) |
Do not allow samplers where they dont belong (variables/return types), fixes #15133
Diffstat (limited to 'servers/visual')
-rw-r--r-- | servers/visual/shader_language.cpp | 34 | ||||
-rw-r--r-- | servers/visual/shader_language.h | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index e2db89e699..3fe661090c 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -691,6 +691,30 @@ String ShaderLanguage::token_debug(const String &p_code) { return output; } +bool ShaderLanguage::is_token_variable_datatype(TokenType p_type) { + return ( + p_type == TK_TYPE_VOID || + p_type == TK_TYPE_BOOL || + p_type == TK_TYPE_BVEC2 || + p_type == TK_TYPE_BVEC3 || + p_type == TK_TYPE_BVEC4 || + p_type == TK_TYPE_INT || + p_type == TK_TYPE_IVEC2 || + p_type == TK_TYPE_IVEC3 || + p_type == TK_TYPE_IVEC4 || + p_type == TK_TYPE_UINT || + p_type == TK_TYPE_UVEC2 || + p_type == TK_TYPE_UVEC3 || + p_type == TK_TYPE_UVEC4 || + p_type == TK_TYPE_FLOAT || + p_type == TK_TYPE_VEC2 || + p_type == TK_TYPE_VEC3 || + p_type == TK_TYPE_VEC4 || + p_type == TK_TYPE_MAT2 || + p_type == TK_TYPE_MAT3 || + p_type == TK_TYPE_MAT4); +} + bool ShaderLanguage::is_token_datatype(TokenType p_type) { return ( @@ -3563,6 +3587,11 @@ Error ShaderLanguage::_parse_block(BlockNode *p_block, const Map<StringName, Bui } } + if (!is_token_variable_datatype(tk.type)) { + _set_error("Invalid data type for variable (samplers not allowed)"); + return ERR_PARSE_ERROR; + } + DataType type = get_token_datatype(tk.type); tk = _get_token(); @@ -4218,6 +4247,11 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct return ERR_PARSE_ERROR; } + if (!is_token_variable_datatype(tk.type)) { + _set_error("Invalid data type for function return (samplers not allowed)"); + return ERR_PARSE_ERROR; + } + type = get_token_datatype(tk.type); _get_completable_identifier(NULL, COMPLETION_MAIN_FUNCTION, name); diff --git a/servers/visual/shader_language.h b/servers/visual/shader_language.h index 08c4d06992..f07b1fade5 100644 --- a/servers/visual/shader_language.h +++ b/servers/visual/shader_language.h @@ -534,6 +534,7 @@ public: static String get_token_text(Token p_token); static bool is_token_datatype(TokenType p_type); + static bool is_token_variable_datatype(TokenType p_type); static DataType get_token_datatype(TokenType p_type); static bool is_token_interpolation(TokenType p_type); static DataInterpolation get_token_interpolation(TokenType p_type); |