Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
de7f8770
Commit
de7f8770
authored
Sep 09, 2016
by
Alexander Barkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-10702 Crash in SET STATEMENT FOR EXECUTE
parent
84940397
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
9 deletions
+92
-9
mysql-test/r/ps_ddl.result
mysql-test/r/ps_ddl.result
+29
-0
mysql-test/t/ps_ddl.test
mysql-test/t/ps_ddl.test
+24
-0
sql/sql_prepare.cc
sql/sql_prepare.cc
+39
-9
No files found.
mysql-test/r/ps_ddl.result
View file @
de7f8770
...
...
@@ -2542,3 +2542,32 @@ EXECUTE stmt3;
EXECUTE stmt3;
DEALLOCATE PREPARE stmt3;
DROP TEMPORARY TABLES tm, t1;
#
# Start of 10.1 tests
#
#
# MDEV-10702 Crash in SET STATEMENT FOR EXECUTE
#
CREATE TABLE t1 (a INT);
PREPARE stmt FROM 'INSERT INTO t1 VALUES (@@max_sort_length)';
SET STATEMENT max_sort_length=2048 FOR EXECUTE stmt;
SELECT * FROM t1;
a
2048
CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.a=NEW.a + 1;
SET STATEMENT max_sort_length=2048 FOR EXECUTE stmt;
SELECT * FROM t1;
a
2048
1025
DROP TRIGGER tr1;
SET STATEMENT max_sort_length=2048 FOR EXECUTE stmt;
SELECT * FROM t1;
a
2048
1025
1024
DROP TABLE t1;
#
# End of 10.1 tests
#
mysql-test/t/ps_ddl.test
View file @
de7f8770
...
...
@@ -2259,3 +2259,27 @@ EXECUTE stmt3;
EXECUTE
stmt3
;
DEALLOCATE
PREPARE
stmt3
;
DROP
TEMPORARY
TABLES
tm
,
t1
;
--
echo
#
--
echo
# Start of 10.1 tests
--
echo
#
--
echo
#
--
echo
# MDEV-10702 Crash in SET STATEMENT FOR EXECUTE
--
echo
#
CREATE
TABLE
t1
(
a
INT
);
PREPARE
stmt
FROM
'INSERT INTO t1 VALUES (@@max_sort_length)'
;
SET
STATEMENT
max_sort_length
=
2048
FOR
EXECUTE
stmt
;
SELECT
*
FROM
t1
;
CREATE
TRIGGER
tr1
BEFORE
INSERT
ON
t1
FOR
EACH
ROW
SET
NEW
.
a
=
NEW
.
a
+
1
;
SET
STATEMENT
max_sort_length
=
2048
FOR
EXECUTE
stmt
;
SELECT
*
FROM
t1
;
DROP
TRIGGER
tr1
;
SET
STATEMENT
max_sort_length
=
2048
FOR
EXECUTE
stmt
;
SELECT
*
FROM
t1
;
DROP
TABLE
t1
;
--
echo
#
--
echo
# End of 10.1 tests
--
echo
#
sql/sql_prepare.cc
View file @
de7f8770
...
...
@@ -3030,7 +3030,36 @@ void mysql_sql_stmt_execute(THD *thd)
DBUG_PRINT
(
"info"
,(
"stmt: 0x%lx"
,
(
long
)
stmt
));
/*
thd->free_list can already have some Items,
e.g. for a query like this:
PREPARE stmt FROM 'INSERT INTO t1 VALUES (@@max_sort_length)';
SET STATEMENT max_sort_length=2048 FOR EXECUTE stmt;
thd->free_list contains a pointer to Item_int corresponding to 2048.
If Prepared_statement::execute() notices that the table metadata for "t1"
has changed since PREPARE, it returns an error asking the calling
Prepared_statement::execute_loop() to re-prepare the statement.
Before returning the error, Prepared_statement::execute()
calls Prepared_statement::cleanup_stmt(),
which calls thd->cleanup_after_query(),
which calls Query_arena::free_items().
We hide "external" Items, e.g. those created while parsing the
"SET STATEMENT" part of the query,
so they don't get freed in case of re-prepare.
See MDEV-10702 Crash in SET STATEMENT FOR EXECUTE
*/
Item
*
free_list_backup
=
thd
->
free_list
;
thd
->
free_list
=
NULL
;
// Hide the external (e.g. "SET STATEMENT") Items
(
void
)
stmt
->
execute_loop
(
&
expanded_query
,
FALSE
,
NULL
,
NULL
);
thd
->
free_items
();
// Free items created by execute_loop()
/*
Now restore the "external" (e.g. "SET STATEMENT") Item list.
It will be freed normaly in THD::cleanup_after_query().
*/
thd
->
free_list
=
free_list_backup
;
stmt
->
lex
->
restore_set_statement_var
();
DBUG_VOID_RETURN
;
}
...
...
@@ -3853,9 +3882,14 @@ Prepared_statement::execute_loop(String *expanded_query,
Reprepare_observer
reprepare_observer
;
bool
error
;
int
reprepare_attempt
=
0
;
#ifndef DBUG_OFF
Item
*
free_list_state
=
thd
->
free_list
;
#endif
/*
- In mysql_sql_stmt_execute() we hide all "external" Items
e.g. those created in the "SET STATEMENT" part of the "EXECUTE" query.
- In case of mysqld_stmt_execute() there should not be "external" Items.
*/
DBUG_ASSERT
(
thd
->
free_list
==
NULL
);
thd
->
select_number
=
select_number_after_prepare
;
/* Check if we got an error when sending long data */
if
(
state
==
Query_arena
::
STMT_ERROR
)
...
...
@@ -3877,12 +3911,8 @@ Prepared_statement::execute_loop(String *expanded_query,
#endif
reexecute:
/*
If the free_list is not empty, we'll wrongly free some externally
allocated items when cleaning up after validation of the prepared
statement.
*/
DBUG_ASSERT
(
thd
->
free_list
==
free_list_state
);
// Make sure that reprepare() did not create any new Items.
DBUG_ASSERT
(
thd
->
free_list
==
NULL
);
/*
Install the metadata observer. If some metadata version is
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment