From 3b24c39294d4ab271680e78a8b417a238c1fe575 Mon Sep 17 00:00:00 2001 From: Maksim Kita Date: Fri, 21 Jan 2022 14:33:57 +0000 Subject: [PATCH] SQLUserDefinedFunctions invalid lambda crash fix --- src/Interpreters/InterpreterCreateFunctionQuery.cpp | 7 ++++++- ...181_sql_user_defined_functions_invalid_lambda.reference | 0 .../02181_sql_user_defined_functions_invalid_lambda.sql | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02181_sql_user_defined_functions_invalid_lambda.reference create mode 100644 tests/queries/0_stateless/02181_sql_user_defined_functions_invalid_lambda.sql diff --git a/src/Interpreters/InterpreterCreateFunctionQuery.cpp b/src/Interpreters/InterpreterCreateFunctionQuery.cpp index 20114fa0d75..f61224b1278 100644 --- a/src/Interpreters/InterpreterCreateFunctionQuery.cpp +++ b/src/Interpreters/InterpreterCreateFunctionQuery.cpp @@ -66,7 +66,12 @@ void InterpreterCreateFunctionQuery::validateFunction(ASTPtr function, const Str for (const auto & argument : tuple_function_arguments.arguments->children) { - const auto & argument_name = argument->as()->name(); + const auto * argument_identifier = argument->as(); + + if (!argument_identifier) + throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "Lambda argument must be identifier"); + + const auto & argument_name = argument_identifier->name(); auto [_, inserted] = arguments.insert(argument_name); if (!inserted) throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "Identifier {} already used as function parameter", argument_name); diff --git a/tests/queries/0_stateless/02181_sql_user_defined_functions_invalid_lambda.reference b/tests/queries/0_stateless/02181_sql_user_defined_functions_invalid_lambda.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/02181_sql_user_defined_functions_invalid_lambda.sql b/tests/queries/0_stateless/02181_sql_user_defined_functions_invalid_lambda.sql new file mode 100644 index 00000000000..ecb5dc8e9f3 --- /dev/null +++ b/tests/queries/0_stateless/02181_sql_user_defined_functions_invalid_lambda.sql @@ -0,0 +1 @@ +CREATE FUNCTION 02181_invalid_lambda AS lambda(((x * 2) AS x_doubled) + x_doubled); --{serverError 1}