[MDEV-24220] Server crash in base_list_iterator::next or in TABLE_LIST::is_recursive_with_table Created: 2020-11-16  Updated: 2020-11-18  Resolved: 2020-11-18

Status: Closed
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.2.37, 10.3.28, 10.4.18, 10.5.9

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: regression


 Description   

CREATE TABLE t (a INT, b INT);
INSERT INTO t VALUES (1,1),(2,2);
CREATE ALGORITHM=MERGE VIEW view1 AS SELECT MAX(a) as f FROM t;
--delimiter $
CREATE PROCEDURE sp()
BEGIN
  SELECT * FROM view1;
  SELECT * FROM x;
END $
--delimiter ;
 
--error ER_NO_SUCH_TABLE
CALL sp;
ALTER TABLE t DROP a;
CALL sp;
 
# Cleanup
DROP PROCEDURE sp;
DROP VIEW view1;
DROP TABLE t;

If it doesn't fail right away, please try an ASAN build.

10.2 debug 9b30212f

#3  <signal handler called>
#4  base_list_iterator::next (this=0x7f6de80b8480) at /data/src/10.2/sql/sql_list.h:470
#5  0x000055727a582787 in List_iterator<TABLE_LIST>::operator++ (this=0x7f6de80b8480) at /data/src/10.2/sql/sql_list.h:580
#6  0x000055727a6d35f9 in st_select_lex::cleanup (this=0x7f6dcc18e2a8) at /data/src/10.2/sql/sql_union.cc:1553
#7  0x000055727a62c87d in mysql_select (thd=0x7f6dcc000d90, tables=0x7f6dcc0966a8, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147749632, result=0x7f6dcc082fc8, unit=0x7f6dcc18db68, select_lex=0x7f6dcc18e2a8) at /data/src/10.2/sql/sql_select.cc:3848
#8  0x000055727a62096a in handle_select (thd=0x7f6dcc000d90, lex=0x7f6dcc18daa8, result=0x7f6dcc082fc8, setup_tables_done_option=0) at /data/src/10.2/sql/sql_select.cc:361
#9  0x000055727a5eb2d1 in execute_sqlcom_select (thd=0x7f6dcc000d90, all_tables=0x7f6dcc0966a8) at /data/src/10.2/sql/sql_parse.cc:6249
#10 0x000055727a5e1c20 in mysql_execute_command (thd=0x7f6dcc000d90) at /data/src/10.2/sql/sql_parse.cc:3558
#11 0x000055727a533812 in sp_instr_stmt::exec_core (this=0x7f6dcc096cd0, thd=0x7f6dcc000d90, nextp=0x7f6de80b95dc) at /data/src/10.2/sql/sp_head.cc:3332
#12 0x000055727a532e67 in sp_lex_keeper::reset_lex_and_exec_core (this=0x7f6dcc096d10, thd=0x7f6dcc000d90, nextp=0x7f6de80b95dc, open_tables=false, instr=0x7f6dcc096cd0) at /data/src/10.2/sql/sp_head.cc:3095
#13 0x000055727a5334b7 in sp_instr_stmt::execute (this=0x7f6dcc096cd0, thd=0x7f6dcc000d90, nextp=0x7f6de80b95dc) at /data/src/10.2/sql/sp_head.cc:3248
#14 0x000055727a52e473 in sp_head::execute (this=0x7f6dcc0957d8, thd=0x7f6dcc000d90, merge_da_on_success=true) at /data/src/10.2/sql/sp_head.cc:1326
#15 0x000055727a53069d in sp_head::execute_procedure (this=0x7f6dcc0957d8, thd=0x7f6dcc000d90, args=0x7f6dcc0056d0) at /data/src/10.2/sql/sp_head.cc:2202
#16 0x000055727a5e0224 in do_execute_sp (thd=0x7f6dcc000d90, sp=0x7f6dcc0957d8) at /data/src/10.2/sql/sql_parse.cc:2980
#17 0x000055727a5e89c3 in mysql_execute_command (thd=0x7f6dcc000d90) at /data/src/10.2/sql/sql_parse.cc:5598
#18 0x000055727a5ef05f in mysql_parse (thd=0x7f6dcc000d90, rawbuf=0x7f6dcc0126f8 "CALL sp", length=7, parser_state=0x7f6de80ba5f0, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:7761
#19 0x000055727a5dd2f4 in dispatch_command (command=COM_QUERY, thd=0x7f6dcc000d90, packet=0x7f6dcc008b51 "CALL sp", packet_length=7, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1827
#20 0x000055727a5dbdef in do_command (thd=0x7f6dcc000d90) at /data/src/10.2/sql/sql_parse.cc:1381
#21 0x000055727a736103 in do_handle_one_connection (connect=0x55727c8c0980) at /data/src/10.2/sql/sql_connect.cc:1336
#22 0x000055727a735e68 in handle_one_connection (arg=0x55727c8c0980) at /data/src/10.2/sql/sql_connect.cc:1241
#23 0x000055727af5d870 in pfs_spawn_thread (arg=0x55727c8a3d40) at /data/src/10.2/storage/perfschema/pfs.cc:1869
#24 0x00007f6ded4ca609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#25 0x00007f6ded0a6293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

10.2 ASAN 9b30212f

==2774987==ERROR: AddressSanitizer: heap-use-after-free on address 0x62500002e1a0 at pc 0x55dd0191f808 bp 0x7f30c45d7490 sp 0x7f30c45d7480
READ of size 8 at 0x62500002e1a0 thread T5
    #0 0x55dd0191f807 in base_list_iterator::next() /data/src/10.2/sql/sql_list.h:470
    #1 0x55dd019d3ad0 in List_iterator<TABLE_LIST>::operator++(int) /data/src/10.2/sql/sql_list.h:580
    #2 0x55dd01d4578d in st_select_lex::cleanup() /data/src/10.2/sql/sql_union.cc:1553
    #3 0x55dd01b87d0c in mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /data/src/10.2/sql/sql_select.cc:3848
    #4 0x55dd01b645fb in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.2/sql/sql_select.cc:361
    #5 0x55dd01adb9e4 in execute_sqlcom_select /data/src/10.2/sql/sql_parse.cc:6249
    #6 0x55dd01ac8929 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:3558
    #7 0x55dd019176bd in sp_instr_stmt::exec_core(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3332
    #8 0x55dd019161de in sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) /data/src/10.2/sql/sp_head.cc:3095
    #9 0x55dd01916f31 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3248
    #10 0x55dd0190b279 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1326
    #11 0x55dd0190fa50 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
    #12 0x55dd01ac48e6 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2980
    #13 0x55dd01ad6a3a in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5598
    #14 0x55dd01ae4f19 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7761
    #15 0x55dd01abe01c in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
    #16 0x55dd01abaddb in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
    #17 0x55dd01e42345 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
    #18 0x55dd01e41c08 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
    #19 0x55dd031dc853 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
    #20 0x7f30cf32c608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
    #21 0x7f30cef06292 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x122292)
 
0x62500002e1a0 is located 4256 bytes inside of 8268-byte region [0x62500002d100,0x62500002f14c)
freed by thread T5 here:
    #0 0x7f30cf8937cf in __interceptor_free (/lib/x86_64-linux-gnu/libasan.so.5+0x10d7cf)
    #1 0x55dd032fa64a in free_memory /data/src/10.2/mysys/safemalloc.c:279
    #2 0x55dd032f9b96 in sf_free /data/src/10.2/mysys/safemalloc.c:197
    #3 0x55dd032c5ede in my_free /data/src/10.2/mysys/my_malloc.c:218
    #4 0x55dd032a3ca7 in free_root /data/src/10.2/mysys/my_alloc.c:395
    #5 0x55dd0190b6e0 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1431
    #6 0x55dd0190fa50 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
    #7 0x55dd01ac48e6 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2980
    #8 0x55dd01ad6a3a in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5598
    #9 0x55dd01ae4f19 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7761
    #10 0x55dd01abe01c in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
    #11 0x55dd01abaddb in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
    #12 0x55dd01e42345 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
    #13 0x55dd01e41c08 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
    #14 0x55dd031dc853 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
    #15 0x7f30cf32c608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
 
previously allocated by thread T5 here:
    #0 0x7f30cf893bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x55dd032f9508 in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
    #2 0x55dd032c546d in my_malloc /data/src/10.2/mysys/my_malloc.c:101
    #3 0x55dd032a2adf in alloc_root /data/src/10.2/mysys/my_alloc.c:243
    #4 0x55dd01af5848 in Query_arena::memdup_w_gap(void const*, unsigned long, unsigned int) /data/src/10.2/sql/sql_class.h:998
    #5 0x55dd01ac2dd3 in alloc_query(THD*, char const*, unsigned int) /data/src/10.2/sql/sql_parse.cc:2686
    #6 0x55dd01916e1d in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3236
    #7 0x55dd0190b279 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1326
    #8 0x55dd0190fa50 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
    #9 0x55dd01ac48e6 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2980
    #10 0x55dd01ad6a3a in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5598
    #11 0x55dd01ae4f19 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7761
    #12 0x55dd01abe01c in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
    #13 0x55dd01abaddb in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
    #14 0x55dd01e42345 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
    #15 0x55dd01e41c08 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
    #16 0x55dd031dc853 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
    #17 0x7f30cf32c608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
 
Thread T5 created by T0 here:
    #0 0x7f30cf7c0805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
    #1 0x55dd031dcc44 in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1919
    #2 0x55dd01860083 in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1246
    #3 0x55dd01877c2b in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6567
    #4 0x55dd018783c6 in create_new_thread /data/src/10.2/sql/mysqld.cc:6637
    #5 0x55dd01879558 in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6895
    #6 0x55dd01876f7c in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6186
    #7 0x55dd0185e93c in main /data/src/10.2/sql/main.cc:25
    #8 0x7f30cee0b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
 
SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.2/sql/sql_list.h:470 in base_list_iterator::next()
Shadow bytes around the buggy address:
  0x0c4a7fffdbe0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdbf0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdc00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdc10: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdc20: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c4a7fffdc30: fd fd fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdc40: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdc50: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdc60: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdc70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c4a7fffdc80: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==2774987==ABORTING

10.4 debug 1bebc8de

#3  <signal handler called>
#4  0x00005651d3c09f4c in TABLE_LIST::is_recursive_with_table (this=0xa5a5a5a5a5a5a5a5) at /data/src/10.4/sql/sql_cte.cc:1146
#5  0x00005651d3acc28c in st_select_lex::cleanup (this=0x7f3e0007a3c0) at /data/src/10.4/sql/sql_union.cc:2089
#6  0x00005651d3a0fe4d in mysql_select (thd=0x7f3e00000d90, tables=0x7f3e0007a990, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147749632, result=0x7f3e00075210, unit=0x7f3e0007bb58, select_lex=0x7f3e0007a3c0) at /data/src/10.4/sql/sql_select.cc:4718
#7  0x00005651d39ff759 in handle_select (thd=0x7f3e00000d90, lex=0x7f3e0007ba98, result=0x7f3e00075210, setup_tables_done_option=0) at /data/src/10.4/sql/sql_select.cc:410
#8  0x00005651d39c488c in execute_sqlcom_select (thd=0x7f3e00000d90, all_tables=0x7f3e0007a990) at /data/src/10.4/sql/sql_parse.cc:6400
#9  0x00005651d39badf9 in mysql_execute_command (thd=0x7f3e00000d90) at /data/src/10.4/sql/sql_parse.cc:3925
#10 0x00005651d38c774a in sp_instr_stmt::exec_core (this=0x7f3e0007b080, thd=0x7f3e00000d90, nextp=0x7f3e110fa07c) at /data/src/10.4/sql/sp_head.cc:3687
#11 0x00005651d38c6ad3 in sp_lex_keeper::reset_lex_and_exec_core (this=0x7f3e0007b0c8, thd=0x7f3e00000d90, nextp=0x7f3e110fa07c, open_tables=false, instr=0x7f3e0007b080) at /data/src/10.4/sql/sp_head.cc:3419
#12 0x00005651d38c72f2 in sp_instr_stmt::execute (this=0x7f3e0007b080, thd=0x7f3e00000d90, nextp=0x7f3e110fa07c) at /data/src/10.4/sql/sp_head.cc:3593
#13 0x00005651d38c09ce in sp_head::execute (this=0x7f3e00079578, thd=0x7f3e00000d90, merge_da_on_success=true) at /data/src/10.4/sql/sp_head.cc:1364
#14 0x00005651d38c3786 in sp_head::execute_procedure (this=0x7f3e00079578, thd=0x7f3e00000d90, args=0x7f3e00005b88) at /data/src/10.4/sql/sp_head.cc:2370
#15 0x00005651d39b8273 in do_execute_sp (thd=0x7f3e00000d90, sp=0x7f3e00079578) at /data/src/10.4/sql/sql_parse.cc:3040
#16 0x00005651d39b8f2b in Sql_cmd_call::execute (this=0x7f3e00013500, thd=0x7f3e00000d90) at /data/src/10.4/sql/sql_parse.cc:3282
#17 0x00005651d39c32eb in mysql_execute_command (thd=0x7f3e00000d90) at /data/src/10.4/sql/sql_parse.cc:6143
#18 0x00005651d39c8897 in mysql_parse (thd=0x7f3e00000d90, rawbuf=0x7f3e00013458 "CALL sp", length=7, parser_state=0x7f3e110fb550, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7938
#19 0x00005651d39b4b9d in dispatch_command (command=COM_QUERY, thd=0x7f3e00000d90, packet=0x7f3e000087b1 "CALL sp", packet_length=7, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1839
#20 0x00005651d39b3405 in do_command (thd=0x7f3e00000d90) at /data/src/10.4/sql/sql_parse.cc:1357
#21 0x00005651d3b42289 in do_handle_one_connection (connect=0x5651d71090b0) at /data/src/10.4/sql/sql_connect.cc:1412
#22 0x00005651d3b41fd2 in handle_one_connection (arg=0x5651d71090b0) at /data/src/10.4/sql/sql_connect.cc:1316
#23 0x00005651d4560f46 in pfs_spawn_thread (arg=0x5651d70568e0) at /data/src/10.4/storage/perfschema/pfs.cc:1869
#24 0x00007f3e179ac609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#25 0x00007f3e17217293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Reproducible with at least MyISAM and InnoDB.
The failure appeared in 10.2 branch after this commit:

commit 190e8a4c2aeb417b405756b193e135c542d46b34
Author: Igor Babaev
Date:   Tue Nov 10 16:02:30 2020 -0800
 
    MDEV-23619 MariaDB crash on WITH RECURSIVE UNION ALL (CTE) query

Non-debug build doesn't crash on my machine, but non-debug ASAN build still produces heap-use-after-free.



 Comments   
Comment by Igor Babaev [ 2020-11-16 ]

This problem can be demonstrated with a more simple test case if the server is built with -DWITH_VALGRIND:bool=1. This test case uses a stored procedure only with the first select from from the SP of the reported test case.

CREATE TABLE t1 (a INT, b INT);
INSERT INTO t1 VALUES (1,1),(2,2);
CREATE VIEW v1 AS SELECT MAX(a) as f FROM t1;
--delimiter $
CREATE PROCEDURE p1()
BEGIN
  SELECT * FROM v1;
END $
--delimiter ;
 
CALL p1;
ALTER TABLE t1 DROP a;
-- error ER_VIEW_INVALID
CALL p1;
 
DROP PROCEDURE p1;
DROP VIEW v1;
DROP TABLE t1;

When running the test with --valgrind we have

worker[1] Using MTR_BUILD_THREAD 300, with reserved ports 16000..16019
main.test_1                              [ fail ]  Found warnings/errors in server log file!
        Test ended at 2020-11-16 14:10:47
line
==28673== Thread 6:
==28673== Invalid read of size 8
==28673==    at 0x6774E5: base_list_iterator::next() (sql_list.h:470)
==28673==    by 0x6C282C: List_iterator<TABLE_LIST>::operator++(int) (sql_list.h:580)
==28673==    by 0x811B17: st_select_lex::cleanup() (sql_union.cc:1553)
==28673==    by 0x76B8AF: mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:3848)
==28673==    by 0x75F863: handle_select(THD*, LEX*, select_result*, unsigned long) (sql_select.cc:373)
==28673==    by 0x72AA1E: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:6249)
==28673==    by 0x72161F: mysql_execute_command(THD*) (sql_parse.cc:3558)
==28673==    by 0x674899: sp_instr_stmt::exec_core(THD*, unsigned int*) (sp_head.cc:3332)
==28673==    by 0x673F0A: sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) (sp_head.cc:3095)
==28673==    by 0x674546: sp_instr_stmt::execute(THD*, unsigned int*) (sp_head.cc:3248)
==28673==    by 0x66F5BD: sp_head::execute(THD*, bool) (sp_head.cc:1326)
==28673==    by 0x6717A0: sp_head::execute_procedure(THD*, List<Item>*) (sp_head.cc:2202)
==28673==    by 0x71FBB0: do_execute_sp(THD*, sp_head*) (sql_parse.cc:2980)
==28673==    by 0x728453: mysql_execute_command(THD*) (sql_parse.cc:5598)
==28673==    by 0x72E78E: mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) (sql_parse.cc:7761)
==28673==    by 0x71CCD7: dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) (sql_parse.cc:1828)
==28673==  Address 0xda59030 is 48 bytes inside a block of size 56 free'd
==28673==    at 0x4C2A37C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28673==    by 0x10DF154: my_free (my_malloc.c:218)
==28673==    by 0x10D288A: free_root (my_alloc.c:395)
==28673==    by 0x66F7B0: sp_head::execute(THD*, bool) (sp_head.cc:1431)
==28673==    by 0x6717A0: sp_head::execute_procedure(THD*, List<Item>*) (sp_head.cc:2202)
==28673==    by 0x71FBB0: do_execute_sp(THD*, sp_head*) (sql_parse.cc:2980)
==28673==    by 0x728453: mysql_execute_command(THD*) (sql_parse.cc:5598)
==28673==    by 0x72E78E: mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) (sql_parse.cc:7761)
==28673==    by 0x71CCD7: dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) (sql_parse.cc:1828)
==28673==    by 0x71B725: do_command(THD*) (sql_parse.cc:1382)
==28673==    by 0x874CC7: do_handle_one_connection(CONNECT*) (sql_connect.cc:1336)
==28673==    by 0x874A3F: handle_one_connection (sql_connect.cc:1241)
==28673==    by 0x108A811: pfs_spawn_thread (pfs.cc:1869)
==28673==    by 0x4E3D0A3: start_thread (in /lib64/libpthread-2.19.so)
==28673==    by 0x6D0A04C: clone (in /lib64/libc-2.19.so)
==28673== Invalid read of size 8
==28673==    at 0x6774BE: base_list_iterator::next() (sql_list.h:468)
==28673==    by 0x6C282C: List_iterator<TABLE_LIST>::operator++(int) (sql_list.h:580)
==28673==    by 0x811B17: st_select_lex::cleanup() (sql_union.cc:1553)
==28673==    by 0x76B8AF: mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) (sql_select.cc:3848)
==28673==    by 0x75F863: handle_select(THD*, LEX*, select_result*, unsigned long) (sql_select.cc:373)
==28673==    by 0x72AA1E: execute_sqlcom_select(THD*, TABLE_LIST*) (sql_parse.cc:6249)
==28673==    by 0x72161F: mysql_execute_command(THD*) (sql_parse.cc:3558)
==28673==    by 0x674899: sp_instr_stmt::exec_core(THD*, unsigned int*) (sp_head.cc:3332)
==28673==    by 0x673F0A: sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) (sp_head.cc:3095)
==28673==    by 0x674546: sp_instr_stmt::execute(THD*, unsigned int*) (sp_head.cc:3248)
==28673==    by 0x66F5BD: sp_head::execute(THD*, bool) (sp_head.cc:1326)
==28673==    by 0x6717A0: sp_head::execute_procedure(THD*, List<Item>*) (sp_head.cc:2202)
==28673==    by 0x71FBB0: do_execute_sp(THD*, sp_head*) (sql_parse.cc:2980)
==28673==    by 0x728453: mysql_execute_command(THD*) (sql_parse.cc:5598)
==28673==    by 0x72E78E: mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) (sql_parse.cc:7761)
==28673==    by 0x71CCD7: dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) (sql_parse.cc:1828)
==28673==  Address 0xda59028 is 40 bytes inside a block of size 56 free'd
==28673==    at 0x4C2A37C: free (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==28673==    by 0x10DF154: my_free (my_malloc.c:218)
==28673==    by 0x10D288A: free_root (my_alloc.c:395)
==28673==    by 0x66F7B0: sp_head::execute(THD*, bool) (sp_head.cc:1431)
==28673==    by 0x6717A0: sp_head::execute_procedure(THD*, List<Item>*) (sp_head.cc:2202)
==28673==    by 0x71FBB0: do_execute_sp(THD*, sp_head*) (sql_parse.cc:2980)
==28673==    by 0x728453: mysql_execute_command(THD*) (sql_parse.cc:5598)
==28673==    by 0x72E78E: mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) (sql_parse.cc:7761)
==28673==    by 0x71CCD7: dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) (sql_parse.cc:1828)
==28673==    by 0x71B725: do_command(THD*) (sql_parse.cc:1382)
==28673==    by 0x874CC7: do_handle_one_connection(CONNECT*) (sql_connect.cc:1336)
==28673==    by 0x874A3F: handle_one_connection (sql_connect.cc:1241)
==28673==    by 0x108A811: pfs_spawn_thread (pfs.cc:1869)
==28673==    by 0x4E3D0A3: start_thread (in /lib64/libpthread-2.19.so)
==28673==    by 0x6D0A04C: clone (in /lib64/libc-2.19.so)
^ Found warnings in /home/igor/maria-git/10.2-mdev-23619/mysql-test/var/log/mysqld.1.err
ok

Comment by Igor Babaev [ 2020-11-16 ]

The above Valgrind report shows that a call of st_select_lex::cleanup attempts to look through a leaf_tables list that contains pointers to some already freed TABLE_LIST object. The debugger shows that this happens for the second call of p1.
The list st_select_lex::leaf_tables is constructed by setup_tables(). If a select query is used in SP and the
server does not find any error in it before the invocation of setup_tables() for the main select then
the leaf_tables list is constructed. This can be seen for the first of p1. For second call of p1 an error is detected when opening the view v1, setup_tables() for the select is never called for the select and st_select_lex::cleanup tries to use the list built for the first call. Yet this list is not valid anymore.

Comment by Oleksandr Byelkin [ 2020-11-18 ]

ok to push

Comment by Igor Babaev [ 2020-11-18 ]

A fix for this bug was pushed into 10.2.

Generated at Thu Feb 08 09:28:20 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.