From e3da362c037af95a85d3054243a4c9a039ceb4b4 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Sun, 22 Sep 2019 21:04:00 +0300 Subject: [PATCH] MDEV-19189 ASAN memcpy-param-overlap in fill_alter_inplace_info upon adding indexes memmove() should be used instead of memcpy() for overlapping memory regions. Overlapping memory regions itself here are fine, because code simply removes one element from arbitrary position of an array. --- .../suite/innodb/r/instant_alter_index_rename.result | 7 +++++++ .../suite/innodb/t/instant_alter_index_rename.test | 10 ++++++++++ sql/sql_table.cc | 8 ++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/innodb/r/instant_alter_index_rename.result b/mysql-test/suite/innodb/r/instant_alter_index_rename.result index 93bbf6ee193..52051eff0bd 100644 --- a/mysql-test/suite/innodb/r/instant_alter_index_rename.result +++ b/mysql-test/suite/innodb/r/instant_alter_index_rename.result @@ -176,3 +176,10 @@ check table rename_column_and_index; Table Op Msg_type Msg_text test.rename_column_and_index check status OK drop table rename_column_and_index; +# +# MDEV-19189: ASAN memcpy-param-overlap in fill_alter_inplace_info upon adding indexes +# +CREATE TABLE t1 (f1 INT, f2 INT, f3 INT); +ALTER TABLE t1 ADD FOREIGN KEY f (f2) REFERENCES xx(f2); +ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t1(f2), ADD KEY (f3), ADD KEY (f1); +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/instant_alter_index_rename.test b/mysql-test/suite/innodb/t/instant_alter_index_rename.test index 3150503c815..3a608a00837 100644 --- a/mysql-test/suite/innodb/t/instant_alter_index_rename.test +++ b/mysql-test/suite/innodb/t/instant_alter_index_rename.test @@ -184,3 +184,13 @@ alter table rename_column_and_index show create table rename_column_and_index; check table rename_column_and_index; drop table rename_column_and_index; + + +--echo # +--echo # MDEV-19189: ASAN memcpy-param-overlap in fill_alter_inplace_info upon adding indexes +--echo # + +CREATE TABLE t1 (f1 INT, f2 INT, f3 INT); +ALTER TABLE t1 ADD FOREIGN KEY f (f2) REFERENCES xx(f2); +ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t1(f2), ADD KEY (f3), ADD KEY (f1); +DROP TABLE t1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 9e44eefbf9b..cf1be27ef3b 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7123,10 +7123,10 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar, --ha_alter_info->index_add_count; --ha_alter_info->index_drop_count; - memcpy(add_buffer + i, add_buffer + i + 1, - sizeof(add_buffer[0]) * (ha_alter_info->index_add_count - i)); - memcpy(drop_buffer + j, drop_buffer + j + 1, - sizeof(drop_buffer[0]) * (ha_alter_info->index_drop_count - j)); + memmove(add_buffer + i, add_buffer + i + 1, + sizeof(add_buffer[0]) * (ha_alter_info->index_add_count - i)); + memmove(drop_buffer + j, drop_buffer + j + 1, + sizeof(drop_buffer[0]) * (ha_alter_info->index_drop_count - j)); --i; // this index once again break; }