1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

MDEV-40854 Use of uninitialized table_will_be_deleted in federated engine

MemorySanitizer report:

==851408==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 ha_federated::end_bulk_insert() storage/federated/ha_federated.cc:2035:30
    #1 mysql_insert(THD*, ...) sql/sql_insert.cc:1258:11
    ...
  Memory was marked as uninitialized
    #0 __msan_allocated_memory
    #1 my_malloc mysys/my_malloc.c:116:7
SUMMARY: MemorySanitizer: use-of-uninitialized-value ... end_bulk_insert()

table_will_be_deleted is a handler member with no in-class
initializer, and the handler object itself is heap-allocated via
my_malloc(), so it starts out as garbage. It was only ever set in
extra(HA_EXTRA_PREPARE_FOR_DROP) and in external_lock(). For a
TEMPORARY table, statement execution can reach end_bulk_insert(),
which reads the flag, without external_lock() having run first, so the
read sees uninitialized memory.

The fix initializes table_will_be_deleted in reset(). Both
ha_federated::open() and ha_federatedx::open() call reset(), so the
flag is initialized on first open and cleared after every statement.
That also covers the first statement after open (e.g. CREATE TEMPORARY
TABLE ... ENGINE=FEDERATED ... SELECT, where external_lock() is not
called).
This commit is contained in:
Aleksey Midenkov
2026-10-20 20:54:50 +03:00
parent b6286fd276
commit 6220bc91c0
4 changed files with 29 additions and 0 deletions

View File

@@ -18,6 +18,18 @@ drop table t1;
select * from fed;
Got one of the listed errors
drop table fed;
#
# MDEV-40854 Use of uninitialized table_will_be_deleted in federated engine
#
create table t1 (c int);
create temporary table t2 (c int) connection='mysql://root@127.0.0.1:MASTER_PORT/test/t1' engine=federated;
insert into t2 values (),();
select * from t1;
c
NULL
NULL
drop tables t1, t2;
# End of 10.11 tests
connection master;
DROP TABLE IF EXISTS federated.t1;
DROP DATABASE IF EXISTS federated;

View File

@@ -21,5 +21,18 @@ drop table t1;
select * from fed;
drop table fed;
--echo #
--echo # MDEV-40854 Use of uninitialized table_will_be_deleted in federated engine
--echo #
create table t1 (c int);
--replace_result $MASTER_MYPORT MASTER_PORT
eval create temporary table t2 (c int) connection='mysql://root@127.0.0.1:$MASTER_MYPORT/test/t1' engine=federated;
insert into t2 values (),();
select * from t1;
drop tables t1, t2;
--echo # End of 10.11 tests
source include/federated_cleanup.inc;

View File

@@ -2974,6 +2974,8 @@ int ha_federated::extra(ha_extra_function operation)
int ha_federated::reset(void)
{
table_will_be_deleted= false;
insert_dup_update= FALSE;
ignore_duplicates= FALSE;
replace_duplicates= FALSE;

View File

@@ -3202,6 +3202,8 @@ int ha_federatedx::reset(void)
THD *thd= ha_thd();
int error = 0;
table_will_be_deleted= false;
insert_dup_update= FALSE;
ignore_duplicates= FALSE;
replace_duplicates= FALSE;