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

ASAN heap-buffer-overflow in Single_line_formatting_helper::on_add_str with optimizer trace

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.4
    • Fix Version/s: 10.4.4
    • Component/s: Optimizer
    • Labels:
      None

      Description

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (a date not null, b time, key(a), key(b)) ENGINE=InnoDB;
      INSERT INTO t1 VALUES ('1991-09-09','00:00:00'),('2032-08-24','02:22:24');
      SET SESSION optimizer_trace = 'enabled=on';
      SELECT * FROM t1 WHERE b IS NULL AND a = '2000-01-01';
       
      DROP TABLE t1;
      

      10.4 ASAN 09b2d37a

      ==10080==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x611000046b3c at pc 0x7fcce534c568 bp 0x7fccd972a760 sp 0x7fccd972a738
      READ of size 141 at 0x611000046b3c thread T27
          #0 0x7fcce534c567 in strlen (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x31567)
          #1 0x55a575cbc83c in Single_line_formatting_helper::on_add_str(char const*, unsigned long) /data/src/10.4/sql/my_json_writer.cc:343
          #2 0x55a575cbbc1d in Json_writer::add_str(char const*) /data/src/10.4/sql/my_json_writer.cc:187
          #3 0x55a575d68f9e in Json_value_helper::add_str(char const*, unsigned long) /data/src/10.4/sql/my_json_writer.h:262
          #4 0x55a576398c33 in Json_writer_array::add(char const*, unsigned long) /data/src/10.4/sql/my_json_writer.h:526
          #5 0x55a5763540c9 in TRP_ROR_INTERSECT::trace_basic_info(PARAM const*, Json_writer_object*) const /data/src/10.4/sql/opt_range.cc:6406
          #6 0x55a576340d15 in SQL_SELECT::test_quick_select(THD*, Bitmap<64u>, unsigned long long, unsigned long long, bool, bool, bool, bool) /data/src/10.4/sql/opt_range.cc:3008
          #7 0x55a5758f3261 in get_quick_record_count /data/src/10.4/sql/sql_select.cc:4629
          #8 0x55a5758f95dc in make_join_statistics /data/src/10.4/sql/sql_select.cc:5355
          #9 0x55a5758db332 in JOIN::optimize_inner() /data/src/10.4/sql/sql_select.cc:2174
          #10 0x55a5758d5312 in JOIN::optimize() /data/src/10.4/sql/sql_select.cc:1551
          #11 0x55a5758f2a93 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.4/sql/sql_select.cc:4571
          #12 0x55a5758c9270 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:424
          #13 0x55a575849fad in execute_sqlcom_select /data/src/10.4/sql/sql_parse.cc:6652
          #14 0x55a575836b74 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:3889
          #15 0x55a575852850 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:8205
          #16 0x55a57582a75b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1829
          #17 0x55a5758275ac in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1358
          #18 0x55a575bbb403 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1399
          #19 0x55a575bbadfc in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1302
          #20 0x55a576782b7e in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #21 0x7fcce5105493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #22 0x7fcce34eb93e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x611000046b3c is located 0 bytes to the right of 252-byte region [0x611000046a40,0x611000046b3c)
      allocated by thread T27 here:
          #0 0x7fcce536f73f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x55a577133073 in sf_malloc /data/src/10.4/mysys/safemalloc.c:118
          #2 0x55a57710396e in my_malloc /data/src/10.4/mysys/my_malloc.c:101
          #3 0x55a575a2dbd3 in Binary_string::realloc_raw(unsigned long) /data/src/10.4/sql/sql_string.cc:101
          #4 0x55a5755b503e in Binary_string::realloc_with_extra(unsigned long) /data/src/10.4/sql/sql_string.h:628
          #5 0x55a5756312ae in Binary_string::realloc_with_extra_if_needed(unsigned long) /data/src/10.4/sql/sql_string.h:640
          #6 0x55a575631162 in Binary_string::append(char const*, unsigned long) /data/src/10.4/sql/sql_string.h:529
          #7 0x55a575a306bb in String::append(char const*, unsigned long) /data/src/10.4/sql/sql_string.cc:536
          #8 0x55a5755b57df in String::append(char const*) /data/src/10.4/sql/sql_string.h:883
          #9 0x55a5763922d1 in print_key_value /data/src/10.4/sql/opt_range.cc:15877
          #10 0x55a5763919b3 in append_range /data/src/10.4/sql/opt_range.cc:15748
          #11 0x55a576354049 in TRP_ROR_INTERSECT::trace_basic_info(PARAM const*, Json_writer_object*) const /data/src/10.4/sql/opt_range.cc:6404
          #12 0x55a576340d15 in SQL_SELECT::test_quick_select(THD*, Bitmap<64u>, unsigned long long, unsigned long long, bool, bool, bool, bool) /data/src/10.4/sql/opt_range.cc:3008
          #13 0x55a5758f3261 in get_quick_record_count /data/src/10.4/sql/sql_select.cc:4629
          #14 0x55a5758f95dc in make_join_statistics /data/src/10.4/sql/sql_select.cc:5355
          #15 0x55a5758db332 in JOIN::optimize_inner() /data/src/10.4/sql/sql_select.cc:2174
          #16 0x55a5758d5312 in JOIN::optimize() /data/src/10.4/sql/sql_select.cc:1551
          #17 0x55a5758f2a93 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.4/sql/sql_select.cc:4571
          #18 0x55a5758c9270 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:424
          #19 0x55a575849fad in execute_sqlcom_select /data/src/10.4/sql/sql_parse.cc:6652
          #20 0x55a575836b74 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:3889
          #21 0x55a575852850 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:8205
          #22 0x55a57582a75b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1829
          #23 0x55a5758275ac in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1358
          #24 0x55a575bbb403 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1399
          #25 0x55a575bbadfc in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1302
          #26 0x55a576782b7e in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #27 0x7fcce5105493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      Thread T27 created by T0 here:
          #0 0x7fcce533ebba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x55a576783146 in spawn_thread_v1 /data/src/10.4/storage/perfschema/pfs.cc:1912
          #2 0x55a575572246 in inline_mysql_thread_create /data/src/10.4/include/mysql/psi/mysql_thread.h:1268
          #3 0x55a575587b38 in create_thread_to_handle_connection(CONNECT*) /data/src/10.4/sql/mysqld.cc:6218
          #4 0x55a57558823d in create_new_thread(CONNECT*) /data/src/10.4/sql/mysqld.cc:6288
          #5 0x55a5755885cd in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /data/src/10.4/sql/mysqld.cc:6386
          #6 0x55a575589219 in handle_connections_sockets() /data/src/10.4/sql/mysqld.cc:6544
          #7 0x55a575587373 in mysqld_main(int, char**) /data/src/10.4/sql/mysqld.cc:5876
          #8 0x55a5755700cf in main /data/src/10.4/sql/main.cc:25
          #9 0x7fcce34232b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
       
      SUMMARY: AddressSanitizer: heap-buffer-overflow ??:0 strlen
      Shadow bytes around the buggy address:
        0x0c2280000d10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c2280000d20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c2280000d30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c2280000d40: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
        0x0c2280000d50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      =>0x0c2280000d60: 00 00 00 00 00 00 00[04]fa fa fa fa fa fa fa fa
        0x0c2280000d70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c2280000d80: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c2280000d90: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
        0x0c2280000da0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c2280000db0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
      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
        Heap right redzone:      fb
        Freed heap region:       fd
        Stack left redzone:      f1
        Stack mid redzone:       f2
        Stack right redzone:     f3
        Stack partial redzone:   f4
        Stack after return:      f5
        Stack use after scope:   f8
        Global redzone:          f9
        Global init order:       f6
        Poisoned by user:        f7
        Contiguous container OOB:fc
        ASan internal:           fe
      ==10080==ABORTING
      

        Attachments

          Activity

            People

            Assignee:
            varun Varun Gupta
            Reporter:
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: