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

runtime error: applying zero offset to null pointer in my_copy_fix_mb on SELECT

    XMLWordPrintable

Details

    Description

      Similar stack to MDEV-35718, however this bug exists in earlier versions also.

      SET @@collation_connection=BINARY;
      SELECT CONVERT(REPLACE (EXPORT_SET ('','','',''),0,'') USING ujis);
      

      Leads to:

      CS 11.8.0 cacaaebf01939d387645fb850ceeec5392496171 (Debug, UBASAN, Clang)

      /test/11.8_dbg_san/strings/ctype-mb.c:337:66: runtime error: applying zero offset to null pointer
          #0 0x55f28e0dcc9b in my_copy_fix_mb /test/11.8_dbg_san/strings/ctype-mb.c:337:66
          #1 0x55f28bc3856e in charset_info_st::copy_fix(char*, unsigned long, char const*, unsigned long, unsigned long, MY_STRCOPY_STATUS*) const /test/11.8_dbg_san/include/m_ctype.h:1046:12
          #2 0x55f28bc3856e in String_copier::well_formed_copy(charset_info_st const*, char*, unsigned long, charset_info_st const*, char const*, unsigned long, unsigned long) /test/11.8_dbg_san/sql/sql_string.cc:1123:26
          #3 0x55f28c7b7908 in String::copy(charset_info_st const*, charset_info_st const*, char const*, unsigned long, unsigned long, String_copier*) /test/11.8_dbg_san/sql/sql_string.h:989:25
          #4 0x55f28c7b7908 in String_copier_for_item::copy_with_warn(charset_info_st const*, String*, charset_info_st const*, char const*, unsigned int, unsigned int) /test/11.8_dbg_san/sql/item.cc:6806:7
          #5 0x55f28cacd267 in Item_func_conv_charset::val_str(String*) /test/11.8_dbg_san/sql/item_strfunc.cc:4004:31
          #6 0x55f28c26335a in Type_handler::Item_send_str(Item*, Protocol*, st_value*) const /test/11.8_dbg_san/sql/sql_type.cc:7664:19
          #7 0x55f28b3c4878 in Protocol::send_result_set_row(List<Item>*) /test/11.8_dbg_san/sql/protocol.cc:1353:15
          #8 0x55f28b6398c3 in select_send::send_data(List<Item>&) /test/11.8_dbg_san/sql/sql_class.cc:3282:17
          #9 0x55f28ba3d331 in JOIN::exec_inner() /test/11.8_dbg_san/sql/sql_select.cc:4911:22
          #10 0x55f28ba39a12 in JOIN::exec() /test/11.8_dbg_san/sql/sql_select.cc:4823:8
          #11 0x55f28b9b3634 in mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /test/11.8_dbg_san/sql/sql_select.cc:5356:21
          #12 0x55f28b9b1f12 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.8_dbg_san/sql/sql_select.cc:633:10
          #13 0x55f28b887167 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/11.8_dbg_san/sql/sql_parse.cc:6191:12
          #14 0x55f28b872d39 in mysql_execute_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:3980:12
          #15 0x55f28b842588 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_dbg_san/sql/sql_parse.cc:7915:18
          #16 0x55f28b83664b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1903:7
          #17 0x55f28b844fad in do_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1416:17
          #18 0x55f28bf0876c in do_handle_one_connection(CONNECT*, bool) /test/11.8_dbg_san/sql/sql_connect.cc:1415:11
          #19 0x55f28bf08027 in handle_one_connection /test/11.8_dbg_san/sql/sql_connect.cc:1327:5
          #20 0x55f28b247b5c in asan_thread_start(void*) asan_interceptors.cpp.o
          #21 0x14b923c9ca93 in start_thread nptl/pthread_create.c:447:8
          #22 0x14b923d29c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: nullptr-with-offset /test/11.8_dbg_san/strings/ctype-mb.c:337:66 
      

      CS 11.8.0 cacaaebf01939d387645fb850ceeec5392496171 (Optimized, UBASAN, Clang)

      /test/11.8_dbg_san/strings/ctype-mb.c:337:66: runtime error: applying zero offset to null pointer
          #0 0x55fcb83d2c9b in my_copy_fix_mb /test/11.8_dbg_san/strings/ctype-mb.c:337:66
          #1 0x55fcb5f2e56e in charset_info_st::copy_fix(char*, unsigned long, char const*, unsigned long, unsigned long, MY_STRCOPY_STATUS*) const /test/11.8_dbg_san/include/m_ctype.h:1046:12
          #2 0x55fcb5f2e56e in String_copier::well_formed_copy(charset_info_st const*, char*, unsigned long, charset_info_st const*, char const*, unsigned long, unsigned long) /test/11.8_dbg_san/sql/sql_string.cc:1123:26
          #3 0x55fcb6aad908 in String::copy(charset_info_st const*, charset_info_st const*, char const*, unsigned long, unsigned long, String_copier*) /test/11.8_dbg_san/sql/sql_string.h:989:25
          #4 0x55fcb6aad908 in String_copier_for_item::copy_with_warn(charset_info_st const*, String*, charset_info_st const*, char const*, unsigned int, unsigned int) /test/11.8_dbg_san/sql/item.cc:6806:7
          #5 0x55fcb6dc3267 in Item_func_conv_charset::val_str(String*) /test/11.8_dbg_san/sql/item_strfunc.cc:4004:31
          #6 0x55fcb655935a in Type_handler::Item_send_str(Item*, Protocol*, st_value*) const /test/11.8_dbg_san/sql/sql_type.cc:7664:19
          #7 0x55fcb56ba878 in Protocol::send_result_set_row(List<Item>*) /test/11.8_dbg_san/sql/protocol.cc:1353:15
          #8 0x55fcb592f8c3 in select_send::send_data(List<Item>&) /test/11.8_dbg_san/sql/sql_class.cc:3282:17
          #9 0x55fcb5d33331 in JOIN::exec_inner() /test/11.8_dbg_san/sql/sql_select.cc:4911:22
          #10 0x55fcb5d2fa12 in JOIN::exec() /test/11.8_dbg_san/sql/sql_select.cc:4823:8
          #11 0x55fcb5ca9634 in mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /test/11.8_dbg_san/sql/sql_select.cc:5356:21
          #12 0x55fcb5ca7f12 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.8_dbg_san/sql/sql_select.cc:633:10
          #13 0x55fcb5b7d167 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/11.8_dbg_san/sql/sql_parse.cc:6191:12
          #14 0x55fcb5b68d39 in mysql_execute_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:3980:12
          #15 0x55fcb5b38588 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_dbg_san/sql/sql_parse.cc:7915:18
          #16 0x55fcb5b2c64b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1903:7
          #17 0x55fcb5b3afad in do_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1416:17
          #18 0x55fcb61fe76c in do_handle_one_connection(CONNECT*, bool) /test/11.8_dbg_san/sql/sql_connect.cc:1415:11
          #19 0x55fcb61fe027 in handle_one_connection /test/11.8_dbg_san/sql/sql_connect.cc:1327:5
          #20 0x55fcb553db5c in asan_thread_start(void*) asan_interceptors.cpp.o
          #21 0x14808789ca93 in start_thread nptl/pthread_create.c:447:8
          #22 0x148087929c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: nullptr-with-offset /test/11.8_dbg_san/strings/ctype-mb.c:337:66 
      

      Setup:

      Compiled with a recent version of Clang (I used Clang 18.1.3) with LLVM 18. Ubuntu instructions:
           # Note: llvm-17-linker-tools installs /usr/lib/llvm-17/lib/LLVMgold.so, which is needed for compilation, and LLVMgold.so is no longer included in LLVM 18
           sudo apt install clang llvm-18 llvm-18-linker-tools llvm-18-runtime llvm-18-tools llvm-18-dev libstdc++-14-dev llvm-dev llvm-17-linker-tools
           sudo ln -s /usr/lib/llvm-17/lib/LLVMgold.so /usr/lib/llvm-18/lib/LLVMgold.so
      Compiled with: "-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C{,XX}_FLAGS='-march=native -mtune=native'" and:
          -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_UBSAN=ON -DWSREP_LIB_WITH_ASAN=ON
      Set before execution:
          export UBSAN_OPTIONS=print_stacktrace=1:report_error_type=1   # And you may also want to supress UBSAN startup issues using 'suppressions=UBSAN.filter' in UBSAN_OPTIONS. For an example of UBSAN.filter, which includes current startup issues see: https://github.com/mariadb-corporation/mariadb-qa/blob/master/UBSAN.filter
          export ASAN_OPTIONS=quarantine_size_mb=512:atexit=0:detect_invalid_pointer_pairs=3:dump_instruction_bytes=1:abort_on_error=1:allocator_may_return_null=1
      

      Bug confirmed present in:
      MariaDB: 10.5.28 (dbg), 10.5.28 (opt), 10.6.21 (dbg), 10.6.21 (opt), 10.11.11 (dbg), 10.11.11 (opt), 11.4.5 (dbg), 11.4.5 (opt), 11.7.2 (dbg), 11.7.2 (opt), 11.8.0 (dbg), 11.8.0 (opt)

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.