Skip to content

Commit e3da362

Browse files
committed
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.
1 parent 5a92ccb commit e3da362

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

mysql-test/suite/innodb/r/instant_alter_index_rename.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,10 @@ check table rename_column_and_index;
176176
Table Op Msg_type Msg_text
177177
test.rename_column_and_index check status OK
178178
drop table rename_column_and_index;
179+
#
180+
# MDEV-19189: ASAN memcpy-param-overlap in fill_alter_inplace_info upon adding indexes
181+
#
182+
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
183+
ALTER TABLE t1 ADD FOREIGN KEY f (f2) REFERENCES xx(f2);
184+
ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t1(f2), ADD KEY (f3), ADD KEY (f1);
185+
DROP TABLE t1;

mysql-test/suite/innodb/t/instant_alter_index_rename.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,13 @@ alter table rename_column_and_index
184184
show create table rename_column_and_index;
185185
check table rename_column_and_index;
186186
drop table rename_column_and_index;
187+
188+
189+
--echo #
190+
--echo # MDEV-19189: ASAN memcpy-param-overlap in fill_alter_inplace_info upon adding indexes
191+
--echo #
192+
193+
CREATE TABLE t1 (f1 INT, f2 INT, f3 INT);
194+
ALTER TABLE t1 ADD FOREIGN KEY f (f2) REFERENCES xx(f2);
195+
ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t1(f2), ADD KEY (f3), ADD KEY (f1);
196+
DROP TABLE t1;

sql/sql_table.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7123,10 +7123,10 @@ static bool fill_alter_inplace_info(THD *thd, TABLE *table, bool varchar,
71237123

71247124
--ha_alter_info->index_add_count;
71257125
--ha_alter_info->index_drop_count;
7126-
memcpy(add_buffer + i, add_buffer + i + 1,
7127-
sizeof(add_buffer[0]) * (ha_alter_info->index_add_count - i));
7128-
memcpy(drop_buffer + j, drop_buffer + j + 1,
7129-
sizeof(drop_buffer[0]) * (ha_alter_info->index_drop_count - j));
7126+
memmove(add_buffer + i, add_buffer + i + 1,
7127+
sizeof(add_buffer[0]) * (ha_alter_info->index_add_count - i));
7128+
memmove(drop_buffer + j, drop_buffer + j + 1,
7129+
sizeof(drop_buffer[0]) * (ha_alter_info->index_drop_count - j));
71307130
--i; // this index once again
71317131
break;
71327132
}

0 commit comments

Comments
 (0)