diff options
author | Michael Widenius <monty@mariadb.org> | 2021-08-25 22:16:19 +0300 |
---|---|---|
committer | Michael Widenius <monty@mariadb.org> | 2021-08-26 07:07:46 +0300 |
commit | b378ddb3d3c3af75195d328018259369671bb029 (patch) | |
tree | ff8b637b1589eec9d22a0b01fbb160b823abc9ab /mysql-test | |
parent | c9851d35adb1675ce204b2c77ac57da9023792ac (diff) | |
download | mariadb-git-b378ddb3d3c3af75195d328018259369671bb029.tar.gz |
MDEV 22785 Crash with prepared statements and NEXTVAL()
The problem was that a PREARE followed by a non prepared statement
using DEFAULT NEXT_VALUE() could change table->next_local to point to
a not persitent memory aria. The next EXECUTE would then try to use
the wrong pointer, which could cause a crash.
Fixed by reseting the pointer to it's old value when doing EXECUTE.
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/suite/sql_sequence/default.result | 10 | ||||
-rw-r--r-- | mysql-test/suite/sql_sequence/default.test | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/mysql-test/suite/sql_sequence/default.result b/mysql-test/suite/sql_sequence/default.result index 37d536d9020..2f048c9e4e2 100644 --- a/mysql-test/suite/sql_sequence/default.result +++ b/mysql-test/suite/sql_sequence/default.result @@ -185,3 +185,13 @@ ALTER TABLE t1 add column d int default next value for s_not_exits; ERROR 42S02: Table 'test.s_not_exits' doesn't exist drop table t1; drop sequence s1; +# +# MDEV 22785 Crash with prepared statements and NEXTVAL() +# +CREATE SEQUENCE s; +CREATE TABLE t1 (id int NOT NULL DEFAULT NEXTVAL(s), PRIMARY KEY (id)); +PREPARE stmt FROM " INSERT INTO t1 () values ()"; +INSERT INTO t1 () values (); +EXECUTE stmt; +DROP TABLE t1; +DROP SEQUENCE s; diff --git a/mysql-test/suite/sql_sequence/default.test b/mysql-test/suite/sql_sequence/default.test index 017165c1a80..e7c13211013 100644 --- a/mysql-test/suite/sql_sequence/default.test +++ b/mysql-test/suite/sql_sequence/default.test @@ -123,3 +123,15 @@ ALTER TABLE t1 add column c int; ALTER TABLE t1 add column d int default next value for s_not_exits; drop table t1; drop sequence s1; + +--echo # +--echo # MDEV 22785 Crash with prepared statements and NEXTVAL() +--echo # +CREATE SEQUENCE s; +CREATE TABLE t1 (id int NOT NULL DEFAULT NEXTVAL(s), PRIMARY KEY (id)); +PREPARE stmt FROM " INSERT INTO t1 () values ()"; +INSERT INTO t1 () values (); +EXECUTE stmt; +# Cleanup +DROP TABLE t1; +DROP SEQUENCE s; |