Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-29256

ASAN heap-use-after-free in String::append_for_single_quote after 2nd execution of ps

    XMLWordPrintable

    Details

      Description

      --source include/have_innodb.inc 
       
      SET in_predicate_conversion_threshold=2;
      SET optimizer_trace='enabled=on';
       
      CREATE TABLE t1 (a VARCHAR(20)) engine=innodb DEFAULT CHARSET=utf8;
      PREPARE stmt FROM "SELECT * FROM t1 WHERE a IN ('1','2')";
      EXECUTE stmt;
      EXECUTE stmt;
      

      10.4 6adfce9c8d2a63a259dd0504600

      Version: '10.4.26-MariaDB-debug-log' 
      =================================================================
      ==1057004==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000052a30 at pc 0x55f5c0c18b6b bp 0x7f82f9c72d30 sp 0x7f82f9c72d20
      READ of size 1 at 0x60c000052a30 thread T27
          #0 0x55f5c0c18b6a in String::append_for_single_quote(char const*, unsigned long) /10.4/src/sql/sql_string.cc:1113
          #1 0x55f5c0c18d78 in String::print(String*) const /10.4/src/sql/sql_string.cc:1130
          #2 0x55f5c115286b in String::print(String*, charset_info_st const*) const /10.4/src/sql/sql_string.h:952
          #3 0x55f5c11fa1b7 in Item_string::print(String*, enum_query_type) /10.4/src/sql/item.cc:3804
          #4 0x55f5c0fb5205 in print_list_item(String*, List<Item>*, enum_query_type) /10.4/src/sql/sql_tvc.cc:456
          #5 0x55f5c0fb545a in table_value_constr::print(THD*, String*, enum_query_type) /10.4/src/sql/sql_tvc.cc:494
          #6 0x55f5c0b636e3 in st_select_lex::print(THD*, String*, enum_query_type) /10.4/src/sql/sql_select.cc:27727
          #7 0x55f5c096e74c in st_select_lex_unit::print(String*, enum_query_type) /10.4/src/sql/sql_lex.cc:3065
          #8 0x55f5c0b62a9e in TABLE_LIST::print(THD*, unsigned long long, String*, enum_query_type) /10.4/src/sql/sql_select.cc:27636
          #9 0x55f5c0b60fed in print_table_array /10.4/src/sql/sql_select.cc:27374
          #10 0x55f5c0b61f18 in print_join /10.4/src/sql/sql_select.cc:27530
          #11 0x55f5c0b6245b in TABLE_LIST::print(THD*, unsigned long long, String*, enum_query_type) /10.4/src/sql/sql_select.cc:27584
          #12 0x55f5c0b612bf in print_table_array /10.4/src/sql/sql_select.cc:27408
          #13 0x55f5c0b61f18 in print_join /10.4/src/sql/sql_select.cc:27530
          #14 0x55f5c0b6438e in st_select_lex::print(THD*, String*, enum_query_type) /10.4/src/sql/sql_select.cc:27849
          #15 0x55f5c0fc717a in opt_trace_print_expanded_query(THD*, st_select_lex*, Json_writer_object*) /10.4/src/sql/opt_trace.cc:115
          #16 0x55f5c0a979cf in JOIN::prepare(TABLE_LIST*, unsigned int, Item*, unsigned int, st_order*, bool, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*) /10.4/src/sql/sql_select.cc:1551
          #17 0x55f5c0aba168 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*) /10.4/src/sql/sql_select.cc:4749
          #18 0x55f5c0a8b281 in handle_select(THD*, LEX*, select_result*, unsigned long) /10.4/src/sql/sql_select.cc:436
          #19 0x55f5c09f94cf in execute_sqlcom_select /10.4/src/sql/sql_parse.cc:6450
          #20 0x55f5c09e6e02 in mysql_execute_command(THD*) /10.4/src/sql/sql_parse.cc:3964
          #21 0x55f5c0a56eec in Prepared_statement::execute(String*, bool) /10.4/src/sql/sql_prepare.cc:5024
          #22 0x55f5c0a523af in Prepared_statement::execute_loop(String*, bool, unsigned char*, unsigned char*) /10.4/src/sql/sql_prepare.cc:4493
          #23 0x55f5c0a4bef0 in mysql_sql_stmt_execute(THD*) /10.4/src/sql/sql_prepare.cc:3577
          #24 0x55f5c09e6e47 in mysql_execute_command(THD*) /10.4/src/sql/sql_parse.cc:3980
          #25 0x55f5c0a029a0 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /10.4/src/sql/sql_parse.cc:7996
          #26 0x55f5c09d9194 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /10.4/src/sql/sql_parse.cc:1857
          #27 0x55f5c09d5c88 in do_command(THD*) /10.4/src/sql/sql_parse.cc:1378
          #28 0x55f5c0dd42f5 in do_handle_one_connection(CONNECT*) /10.4/src/sql/sql_connect.cc:1420
          #29 0x55f5c0dd3a4e in handle_one_connection /10.4/src/sql/sql_connect.cc:1316
          #30 0x55f5c1a5f9fc in pfs_spawn_thread /10.4/src/storage/perfschema/pfs.cc:1869
          #31 0x7f831084a608 in start_thread /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477
          #32 0x7f831041b132 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x11f132)
       
      0x60c000052a30 is located 112 bytes inside of 124-byte region [0x60c0000529c0,0x60c000052a3c)
      freed by thread T27 here:
          #0 0x7f8310e4840f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:122
          #1 0x55f5c25edec9 in free_memory /10.4/src/mysys/safemalloc.c:279
          #2 0x55f5c25ed485 in sf_free /10.4/src/mysys/safemalloc.c:197
          #3 0x55f5c25bbe83 in my_free /10.4/src/mysys/my_malloc.c:222
          #4 0x55f5c06fce31 in Binary_string::free() /10.4/src/sql/sql_string.h:610
          #5 0x55f5c06fcc1d in Binary_string::~Binary_string() /10.4/src/sql/sql_string.h:420
          #6 0x55f5c06fd00f in String::~String() /10.4/src/sql/sql_string.h:728
          #7 0x55f5c072943a in Item::~Item() /10.4/src/sql/item.h:944
          #8 0x55f5c072cc58 in Item_basic_value::~Item_basic_value() /10.4/src/sql/item.h:2764
          #9 0x55f5c072ce5e in Item_basic_constant::~Item_basic_constant() /10.4/src/sql/item.h:2825
          #10 0x55f5c072d026 in Item_literal::~Item_literal() /10.4/src/sql/item.h:3214
          #11 0x55f5c072dfd8 in Item_string::~Item_string() /10.4/src/sql/item.h:4393
          #12 0x55f5c072e005 in Item_string::~Item_string() /10.4/src/sql/item.h:4393
          #13 0x55f5c08ee39a in Item::delete_self() /10.4/src/sql/item.h:2244
          #14 0x55f5c08d26ea in Query_arena::free_items() /10.4/src/sql/sql_class.cc:3915
          #15 0x55f5c08c2b1c in THD::cleanup_after_query() /10.4/src/sql/sql_class.cc:2286
          #16 0x55f5c0a4f7ab in Prepared_statement::cleanup_stmt() /10.4/src/sql/sql_prepare.cc:4107
          #17 0x55f5c0a5727c in Prepared_statement::execute(String*, bool) /10.4/src/sql/sql_prepare.cc:5052
          #18 0x55f5c0a523af in Prepared_statement::execute_loop(String*, bool, unsigned char*, unsigned char*) /10.4/src/sql/sql_prepare.cc:4493
          #19 0x55f5c0a4bef0 in mysql_sql_stmt_execute(THD*) /10.4/src/sql/sql_prepare.cc:3577
          #20 0x55f5c09e6e47 in mysql_execute_command(THD*) /10.4/src/sql/sql_parse.cc:3980
          #21 0x55f5c0a029a0 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /10.4/src/sql/sql_parse.cc:7996
          #22 0x55f5c09d9194 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /10.4/src/sql/sql_parse.cc:1857
          #23 0x55f5c09d5c88 in do_command(THD*) /10.4/src/sql/sql_parse.cc:1378
          #24 0x55f5c0dd42f5 in do_handle_one_connection(CONNECT*) /10.4/src/sql/sql_connect.cc:1420
          #25 0x55f5c0dd3a4e in handle_one_connection /10.4/src/sql/sql_connect.cc:1316
          #26 0x55f5c1a5f9fc in pfs_spawn_thread /10.4/src/storage/perfschema/pfs.cc:1869
          #27 0x7f831084a608 in start_thread /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477
       
      previously allocated by thread T27 here:
          #0 0x7f8310e48808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
          #1 0x55f5c25ece39 in sf_malloc /10.4/src/mysys/safemalloc.c:118
          #2 0x55f5c25bb38c in my_malloc /10.4/src/mysys/my_malloc.c:101
          #3 0x55f5c0c133a7 in Binary_string::real_alloc(unsigned long) /10.4/src/sql/sql_string.cc:44
          #4 0x55f5c07223c7 in Binary_string::alloc(unsigned long) /10.4/src/sql/sql_string.h:619
          #5 0x55f5c0c15672 in String::copy(char const*, unsigned long, charset_info_st const*, charset_info_st const*, unsigned int*) /10.4/src/sql/sql_string.cc:454
          #6 0x55f5c0c1998d in String::copy(String const*, charset_info_st const*, unsigned int*) /10.4/src/sql/sql_string.h:853
          #7 0x55f5c123bddc in Item_string::Item_string(THD*, String const*, charset_info_st const*, unsigned int*, Derivation, unsigned int) /10.4/src/sql/item.h:4445
          #8 0x55f5c11e47ae in Item::const_charset_converter(THD*, charset_info_st const*, bool, char const*) /10.4/src/sql/item.cc:1364
          #9 0x55f5c072bfd4 in Item::const_charset_converter(THD*, charset_info_st const*, bool) /10.4/src/sql/item.h:2240
          #10 0x55f5c072df0a in Item_string::safe_charset_converter(THD*, charset_info_st const*) /10.4/src/sql/item.h:4491
          #11 0x55f5c11ef0b1 in Type_std_attributes::agg_item_set_converter(DTCollation const&, char const*, Item**, unsigned int, unsigned int, int) /10.4/src/sql/item.cc:2572
          #12 0x55f5c0f731c4 in Type_std_attributes::agg_arg_charsets(DTCollation&, char const*, Item**, unsigned int, unsigned int, int) /10.4/src/sql/sql_type.h:3082
          #13 0x55f5c0f73278 in Type_std_attributes::agg_arg_charsets_for_comparison(DTCollation&, char const*, Item**, unsigned int, int) /10.4/src/sql/sql_type.h:3130
          #14 0x55f5c0f7db43 in Item_func_or_sum::agg_arg_charsets_for_comparison(DTCollation&, Item**, unsigned int, int) /10.4/src/sql/item.h:5226
          #15 0x55f5c0f813af in Item_func_in::agg_all_arg_charsets_for_comparison() (/home/alice/am/_depot/m-branch/m4-10.4-bld/sql/mysqld+0x18933af)
          #16 0x55f5c0f526c5 in Type_handler_string_result::Item_func_in_fix_comparator_compatible_types(THD*, Item_func_in*) const /10.4/src/sql/sql_type.cc:5377
          #17 0x55f5c127bb19 in Item_func_in::fix_length_and_dec() /10.4/src/sql/item_cmpfunc.cc:4410
          #18 0x55f5c12e1ac7 in Item_func::fix_fields(THD*, Item**) /10.4/src/sql/item_func.cc:370
          #19 0x55f5c127b0f6 in Item_func_in::fix_fields(THD*, Item**) /10.4/src/sql/item_cmpfunc.cc:4335
          #20 0x55f5c0748018 in Item::fix_fields_if_needed(THD*, Item**) /10.4/src/sql/item.h:964
          #21 0x55f5c0748052 in Item::fix_fields_if_needed_for_scalar(THD*, Item**) (/home/alice/am/_depot/m-branch/m4-10.4-bld/sql/mysqld+0x105a052)
          #22 0x55f5c087d05a in Item::fix_fields_if_needed_for_bool(THD*, Item**) /10.4/src/sql/item.h:972
          #23 0x55f5c0873c43 in setup_conds(THD*, TABLE_LIST*, List<TABLE_LIST>&, Item**) /10.4/src/sql/sql_base.cc:8515
          #24 0x55f5c0a8d2f3 in setup_without_group /10.4/src/sql/sql_select.cc:739
          #25 0x55f5c0a94703 in JOIN::prepare(TABLE_LIST*, unsigned int, Item*, unsigned int, st_order*, bool, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*) /10.4/src/sql/sql_select.cc:1298
          #26 0x55f5c0aba168 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*) /10.4/src/sql/sql_select.cc:4749
          #27 0x55f5c0a8b281 in handle_select(THD*, LEX*, select_result*, unsigned long) /10.4/src/sql/sql_select.cc:436
          #28 0x55f5c09f94cf in execute_sqlcom_select /10.4/src/sql/sql_parse.cc:6450
          #29 0x55f5c09e6e02 in mysql_execute_command(THD*) /10.4/src/sql/sql_parse.cc:3964
       
      Thread T27 created by T0 here:
          #0 0x7f8310d75815 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cc:208
          #1 0x55f5c1a5fded in spawn_thread_v1 /10.4/src/storage/perfschema/pfs.cc:1919
          #2 0x55f5c06d7bdf in inline_mysql_thread_create /10.4/src/include/mysql/psi/mysql_thread.h:1275
          #3 0x55f5c06efd57 in create_thread_to_handle_connection(CONNECT*) /10.4/src/sql/mysqld.cc:6282
          #4 0x55f5c06f04f2 in create_new_thread(CONNECT*) /10.4/src/sql/mysqld.cc:6352
          #5 0x55f5c06f09d8 in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /10.4/src/sql/mysqld.cc:6450
          #6 0x55f5c06f1894 in handle_connections_sockets() /10.4/src/sql/mysqld.cc:6608
          #7 0x55f5c06ef45c in mysqld_main(int, char**) /10.4/src/sql/mysqld.cc:5940
          #8 0x55f5c06d5e2c in main /10.4/src/sql/main.cc:25
          #9 0x7f8310320082 in __libc_start_main ../csu/libc-start.c:308
       
      SUMMARY: AddressSanitizer: heap-use-after-free /10.4/src/sql/sql_string.cc:1113 in String::append_for_single_quote(char const*, unsigned long)
      Shadow bytes around the buggy address:
        0x0c18800024f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04
        0x0c1880002500: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
        0x0c1880002510: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
        0x0c1880002520: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04
        0x0c1880002530: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
      =>0x0c1880002540: fd fd fd fd fd fd[fd]fd fa fa fa fa fa fa fa fa
        0x0c1880002550: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c1880002560: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
        0x0c1880002570: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
        0x0c1880002580: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c1880002590: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
      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
      ==1057004==ABORTING
      ----------SERVER LOG END-------------
      

        Attachments

          Activity

            People

            Assignee:
            sanja Oleksandr Byelkin
            Reporter:
            alice Alice Sherepa
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.