From c1cabb0bf554f31df00ce3925a23cffade4de280 Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Sun, 6 Oct 2019 20:35:41 +0300 Subject: [PATCH] Prevent shader crash if name of variable overrides function name (cherry picked from commit 76324bec8d269330c59812bfcc852a195304aa92) --- servers/visual/shader_language.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 9ab7206c75b..db9173e7b0c 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -2848,6 +2848,16 @@ ShaderLanguage::Node *ShaderLanguage::_parse_expression(BlockNode *p_block, cons bool ok = _parse_function_arguments(p_block, p_builtin_types, func, &carg); + // Check if block has a variable with the same name as function to prevent shader crash. + ShaderLanguage::BlockNode *bnode = p_block; + while (bnode) { + if (bnode->variables.has(name)) { + _set_error("Expected function name"); + return NULL; + } + bnode = bnode->parent_block; + } + //test if function was parsed first for (int i = 0; i < shader->functions.size(); i++) { if (shader->functions[i].name == name) {