From 21e79331c8c89e397d5a1ca4a4b8a70ad7c0377a Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Sat, 13 Jun 2020 16:45:55 +0300 Subject: MDEV-22779: Crash: Prepared Statement with a '?' parameter inside a re-used CTE When a prepared statement parameter '?' is used in a CTE that is used multiple times, the following happens: - The CTE definition is re-parsed multiple times. - There are multiple Item_param objects referring to the same "?" in the original query. - Prepared_statement::param has a pointer to the first of them, the others are "clones". - When prepared statement parameter gets the value, it should be passed over to clones with param->sync_clones() call. This call is made in insert_params(), etc. It was not made in insert_params_with_log(). This would cause Item_param to not have any value which would confuse the query optimizer. Added the missing call. --- tests/mysql_client_test.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests') diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index c544e20f2fe..33655b80662 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -19843,6 +19843,57 @@ static void test_bulk_replace() } #endif + +static void test_ps_params_in_ctes() +{ + int rc; + const char *query; + MYSQL_BIND ps_params[1]; + int int_data[1]; + MYSQL_STMT *stmt; + + rc= mysql_query(mysql, "create table t1(a int, b int, key(a))"); + myquery(rc); + + rc= mysql_query(mysql, "insert into t1 (a) values " + "(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)"); + myquery(rc); + + query= + "explain " + "with T as " + "( " + " select * from t1 where t1.a=? limit 2 " + ") " + "select * from T as TA, T as TB;"; + + stmt= mysql_stmt_init(mysql); + check_stmt(stmt); + + rc= mysql_stmt_prepare(stmt, query, (uint) strlen(query)); + check_execute(stmt, rc); + + int_data[0]=2; + + ps_params[0].buffer_type= MYSQL_TYPE_LONG; + ps_params[0].buffer= (char *) &int_data[0]; + ps_params[0].length= 0; + ps_params[0].is_null= 0; + + rc= mysql_stmt_bind_param(stmt, ps_params); + check_execute(stmt, rc); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + rc= mysql_stmt_store_result(stmt); + check_execute(stmt, rc); + + rc= mysql_query(mysql, "drop table t1"); + myquery(rc); +} + + static struct my_tests_st my_tests[]= { { "disable_query_logs", disable_query_logs }, { "test_view_sp_list_fields", test_view_sp_list_fields }, @@ -20127,6 +20178,7 @@ static struct my_tests_st my_tests[]= { { "test_bulk_delete", test_bulk_delete }, { "test_bulk_replace", test_bulk_replace }, #endif + { "test_ps_params_in_ctes", test_ps_params_in_ctes }, { 0, 0 } }; -- cgit v1.2.1 From 37c88445e30d52c965bcb19b19fa710c3eb4fad9 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Tue, 31 Mar 2020 07:57:53 +1100 Subject: mtr: use env for perl On FreeBSD, perl isn't in /usr/bin, its in /usr/local/bin or elsewhere in the path. Like storage/{maria/unittest/,}ma_test_* , we use /usr/bin/env to find perl and run it. --- tests/big_record.pl | 2 +- tests/drop_test.pl | 2 +- tests/export.pl | 2 +- tests/fork2_test.pl | 2 +- tests/fork_big.pl | 2 +- tests/fork_big2.pl | 2 +- tests/grant.pl | 2 +- tests/index_corrupt.pl | 2 +- tests/insert_and_repair.pl | 2 +- tests/lock_test.pl | 2 +- tests/mail_to_db.pl | 2 +- tests/pmail.pl | 2 +- tests/rename_test.pl | 2 +- tests/table_types.pl | 2 +- tests/test_delayed_insert.pl | 2 +- tests/truncate.pl | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) (limited to 'tests') diff --git a/tests/big_record.pl b/tests/big_record.pl index cb1f8998468..b08f7ea60e2 100755 --- a/tests/big_record.pl +++ b/tests/big_record.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. # diff --git a/tests/drop_test.pl b/tests/drop_test.pl index 329f65eb65d..e4ae5a2671f 100755 --- a/tests/drop_test.pl +++ b/tests/drop_test.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (C) 2000 MySQL AB # Use is subject to license terms diff --git a/tests/export.pl b/tests/export.pl index f99798ecac8..dace79feb30 100755 --- a/tests/export.pl +++ b/tests/export.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (C) 2000, 2001 MySQL AB # Use is subject to license terms diff --git a/tests/fork2_test.pl b/tests/fork2_test.pl index 356055733fa..a05a9b96679 100755 --- a/tests/fork2_test.pl +++ b/tests/fork2_test.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (C) 2000, 2001 MySQL AB # Use is subject to license terms diff --git a/tests/fork_big.pl b/tests/fork_big.pl index 623377ab5cd..b5f8770c903 100755 --- a/tests/fork_big.pl +++ b/tests/fork_big.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w use strict; # Copyright (c) 2001, 2006 MySQL AB diff --git a/tests/fork_big2.pl b/tests/fork_big2.pl index c844d290834..7f055609108 100644 --- a/tests/fork_big2.pl +++ b/tests/fork_big2.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (c) 2002, 2003, 2005, 2006 MySQL AB # Use is subject to license terms diff --git a/tests/grant.pl b/tests/grant.pl index cd651643316..b50481a93fc 100755 --- a/tests/grant.pl +++ b/tests/grant.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (c) 2000, 2005 MySQL AB, 2009 Sun Microsystems, Inc. # Use is subject to license terms. diff --git a/tests/index_corrupt.pl b/tests/index_corrupt.pl index 6b04ce8a59c..8194982755a 100755 --- a/tests/index_corrupt.pl +++ b/tests/index_corrupt.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (C) 2005 MySQL AB # Use is subject to license terms diff --git a/tests/insert_and_repair.pl b/tests/insert_and_repair.pl index 18091c92718..91333746e79 100755 --- a/tests/insert_and_repair.pl +++ b/tests/insert_and_repair.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (C) 2000, 2001 MySQL AB # Use is subject to license terms diff --git a/tests/lock_test.pl b/tests/lock_test.pl index 98c4ad6377d..8a8a0322467 100755 --- a/tests/lock_test.pl +++ b/tests/lock_test.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (C) 2000 MySQL AB # Use is subject to license terms diff --git a/tests/mail_to_db.pl b/tests/mail_to_db.pl index e50415d96f3..6e5c115f543 100755 --- a/tests/mail_to_db.pl +++ b/tests/mail_to_db.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright Abandoned 1998 TCX DataKonsult AB & Monty Program KB & Detron HB # This file is public domain and comes with NO WARRANTY of any kind # diff --git a/tests/pmail.pl b/tests/pmail.pl index 359256c25b3..97e5914f794 100755 --- a/tests/pmail.pl +++ b/tests/pmail.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (C) 2000, 2005 MySQL AB # Use is subject to license terms diff --git a/tests/rename_test.pl b/tests/rename_test.pl index d7097df1e4e..ec7254a4cf6 100755 --- a/tests/rename_test.pl +++ b/tests/rename_test.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (C) 2000, 2001 MySQL AB # Use is subject to license terms diff --git a/tests/table_types.pl b/tests/table_types.pl index c633a153098..782b8f254bf 100755 --- a/tests/table_types.pl +++ b/tests/table_types.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (C) 2000, 2003 MySQL AB # Use is subject to license terms diff --git a/tests/test_delayed_insert.pl b/tests/test_delayed_insert.pl index cb5b86a228d..2f8f97b25c6 100755 --- a/tests/test_delayed_insert.pl +++ b/tests/test_delayed_insert.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (C) 2000, 2001 MySQL AB # Use is subject to license terms diff --git a/tests/truncate.pl b/tests/truncate.pl index 98791a15b2c..e83ebab9291 100755 --- a/tests/truncate.pl +++ b/tests/truncate.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl -w +#!/usr/bin/env perl -w # Copyright (C) 2002 MySQL AB # Use is subject to license terms -- cgit v1.2.1 From 9ed50ece339358fcd5ebd8089f3c780a75b5f520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Wed, 1 Jul 2020 17:18:47 +0300 Subject: MDEV-22779: Fix a memory leak in the unit test --- tests/mysql_client_test.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 33655b80662..ec878ae830c 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -19889,6 +19889,8 @@ static void test_ps_params_in_ctes() rc= mysql_stmt_store_result(stmt); check_execute(stmt, rc); + mysql_stmt_close(stmt); + rc= mysql_query(mysql, "drop table t1"); myquery(rc); } -- cgit v1.2.1