From eb2550ee78898ff7129073a3ae5c6c17096fafca Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Mon, 12 Apr 2021 13:16:20 +0300 Subject: [PATCH] MDEV-25346: JSON_TABLE: Server crashes in Item_field::fix_outer_field ... Use a function instead of lambda (TODO: squash this with previous patch for MDEV-25346) --- sql/sql_derived.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 90e0b6068f9..29741cb1adb 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -23,7 +23,6 @@ #include "mariadb.h" /* NO_EMBEDDED_ACCESS_CHECKS */ -#include #include "sql_priv.h" #include "unireg.h" #include "sql_derived.h" @@ -597,6 +596,25 @@ bool mysql_derived_init(THD *thd, LEX *lex, TABLE_LIST *derived) } +/* + @brief + Reset the Name_resolution_context::outer_context for all ON expression + contexts in the given nested join. Do this recursively for all nested joins + it contains. +*/ + +static void reset_on_clauses_context(List& join_list) +{ + List_iterator li(join_list); + while (TABLE_LIST *table= li++) + { + if (table->on_context) + table->on_context->outer_context= NULL; + if (table->nested_join) + reset_on_clauses_context(table->nested_join->join_list); + } +} + /* Create temporary table structure (but do not fill it) @@ -765,19 +783,7 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) sl->context.outer_context= 0; // And for ON clauses, if there are any - std::function&)> reset_context= - [&](List &join_list) - { - List_iterator li(join_list); - while (TABLE_LIST *table= li++) - { - if (table->on_context) - table->on_context->outer_context= NULL; - if (table->nested_join) - reset_context(table->nested_join->join_list); - } - }; - reset_context(*sl->join_list); + reset_on_clauses_context(*sl->join_list); if (!derived->is_with_table_recursive_reference() || (!derived->with->with_anchor &&