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

UBSAN: runtime error: applying zero offset to null pointer

    XMLWordPrintable

Details

    Description

      Possibly related to MDEV-35725, however testcase is different

      SET NAMES sjis;
      SELECT * FROM mysql.user;
      

      Leads to:

      CS 11.8.0 7734c85c31c9e292ef1133115fba2f7edd71dd51 (Debug, UBASAN, Clang)

      /test/11.8_dbg_san/strings/ctype.c:1157:46: runtime error: applying zero offset to null pointer
          #0 0x559ed8a777aa in my_convert_using_func /test/11.8_dbg_san/strings/ctype.c:1157:46
          #1 0x559ed8a781ae in my_convert /test/11.8_dbg_san/strings/ctype.c:1236:12
          #2 0x559ed1ad2191 in copy_and_convert(char*, unsigned long, charset_info_st const*, char const*, unsigned long, charset_info_st const*, unsigned int*) /test/11.8_dbg_san/sql/sql_string.h:53:10
          #3 0x559ed1ad1cc3 in Protocol::net_store_data_cs(unsigned char const*, unsigned long, charset_info_st const*, charset_info_st const*) /test/11.8_dbg_san/sql/protocol.cc:114:8
          #4 0x559ed1afca47 in Protocol::store_string_aux(char const*, unsigned long, charset_info_st const*, charset_info_st const*) /test/11.8_dbg_san/sql/protocol.cc:1455:12
          #5 0x559ed1afed66 in Protocol_text::store_str(char const*, unsigned long, charset_info_st const*, charset_info_st const*) /test/11.8_dbg_san/sql/protocol.cc:1494:10
          #6 0x559ed1afb472 in Protocol::store(char const*, unsigned long, charset_info_st const*) /test/11.8_dbg_san/sql/protocol.h:153:12
          #7 0x559ed3f4c335 in Type_handler::Item_send_str(Item*, Protocol*, st_value*) const /test/11.8_dbg_san/sql/sql_type.cc:7667:22
          #8 0x559ed369217c in Type_handler_string_result::Item_send(Item*, Protocol*, st_value*) const /test/11.8_dbg_san/sql/sql_type.h:5745:12
          #9 0x559ed1850617 in Item::send(Protocol*, st_value*) /test/11.8_dbg_san/sql/item.h:1256:28
          #10 0x559ed4e28952 in Item_ref::send(Protocol*, st_value*) /test/11.8_dbg_san/sql/item.cc:8681:18
          #11 0x559ed4e4dbb5 in Item_direct_view_ref::send(Protocol*, st_value*) /test/11.8_dbg_san/sql/item.cc:9453:27
          #12 0x559ed1afa681 in Protocol::send_result_set_row(List<Item>*) /test/11.8_dbg_san/sql/protocol.cc:1353:15
          #13 0x559ed213704a in select_send::send_data(List<Item>&) /test/11.8_dbg_san/sql/sql_class.cc:3275:17
          #14 0x559ed2b38fd0 in select_result_sink::send_data_with_check(List<Item>&, st_select_lex_unit*, unsigned long long) /test/11.8_dbg_san/sql/sql_class.h:6244:12
          #15 0x559ed2afcb96 in end_send(JOIN*, st_join_table*, bool) /test/11.8_dbg_san/sql/sql_select.cc:25427:9
          #16 0x559ed2cc8098 in evaluate_join_record(JOIN*, st_join_table*, int) /test/11.8_dbg_san/sql/sql_select.cc:24329:11
          #17 0x559ed29c55b1 in sub_select(JOIN*, st_join_table*, bool) /test/11.8_dbg_san/sql/sql_select.cc:24096:9
          #18 0x559ed2b40a95 in do_select(JOIN*, Procedure*) /test/11.8_dbg_san/sql/sql_select.cc:23607:14
          #19 0x559ed2b36e79 in JOIN::exec_inner() /test/11.8_dbg_san/sql/sql_select.cc:5037:50
          #20 0x559ed2b2f56a in JOIN::exec() /test/11.8_dbg_san/sql/sql_select.cc:4820:8
          #21 0x559ed29cda79 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:5353:21
          #22 0x559ed29c9137 in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.8_dbg_san/sql/sql_select.cc:633:10
          #23 0x559ed26b4ee0 in execute_sqlcom_select(THD*, TABLE_LIST*) /test/11.8_dbg_san/sql/sql_parse.cc:6177:12
          #24 0x559ed2654dcc in mysql_execute_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:3966:12
          #25 0x559ed25faef9 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_dbg_san/sql/sql_parse.cc:7901:18
          #26 0x559ed25dbdb8 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1903:7
          #27 0x559ed2604e56 in do_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1416:17
          #28 0x559ed3767556 in do_handle_one_connection(CONNECT*, bool) /test/11.8_dbg_san/sql/sql_connect.cc:1415:11
          #29 0x559ed3765d19 in handle_one_connection /test/11.8_dbg_san/sql/sql_connect.cc:1327:5
          #30 0x559ed17ae5fc in asan_thread_start(void*) asan_interceptors.cpp.o
          #31 0x15179189ca93 in start_thread nptl/pthread_create.c:447:8
          #32 0x151791929c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: nullptr-with-offset /test/11.8_dbg_san/strings/ctype.c:1157:46 
      

      CS 11.8.0 7734c85c31c9e292ef1133115fba2f7edd71dd51 (Optimized, UBASAN, Clang)

      /test/11.8_opt_san/strings/ctype.c:1157:46: runtime error: applying zero offset to null pointer
          #0 0x559a8d0744a6 in my_convert_using_func /test/11.8_opt_san/strings/ctype.c:1157:46
          #1 0x559a8d074835 in my_convert /test/11.8_opt_san/strings/ctype.c:1236:12
          #2 0x559a89e6cc7f in copy_and_convert(char*, unsigned long, charset_info_st const*, char const*, unsigned long, charset_info_st const*, unsigned int*) /test/11.8_opt_san/sql/sql_string.h:53:10
          #3 0x559a89e6cc7f in Protocol::net_store_data_cs(unsigned char const*, unsigned long, charset_info_st const*, charset_info_st const*) /test/11.8_opt_san/sql/protocol.cc:114:8
          #4 0x559a89e7fe04 in Protocol::send_result_set_row(List<Item>*) /test/11.8_opt_san/sql/protocol.cc:1353:15
          #5 0x559a8a1496a3 in select_send::send_data(List<Item>&) /test/11.8_opt_san/sql/sql_class.cc:3275:17
          #6 0x559a8a5d81f2 in end_send(JOIN*, st_join_table*, bool) /test/11.8_opt_san/sql/sql_select.cc:25427:9
          #7 0x559a8a6b725f in evaluate_join_record(JOIN*, st_join_table*, int) /test/11.8_opt_san/sql/sql_select.cc:24329:11
          #8 0x559a8a547cfe in sub_select(JOIN*, st_join_table*, bool) /test/11.8_opt_san/sql/sql_select.cc:24096:9
          #9 0x559a8a5f74e4 in do_select(JOIN*, Procedure*) /test/11.8_opt_san/sql/sql_select.cc:23607:14
          #10 0x559a8a5f212c in JOIN::exec_inner() /test/11.8_opt_san/sql/sql_select.cc:5037:50
          #11 0x559a8a5efe21 in JOIN::exec() /test/11.8_opt_san/sql/sql_select.cc:4820:8
          #12 0x559a8a54ca2b 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_opt_san/sql/sql_select.cc:5353:21
          #13 0x559a8a54ac4d in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.8_opt_san/sql/sql_select.cc:633:10
          #14 0x559a8a3fedac in execute_sqlcom_select(THD*, TABLE_LIST*) /test/11.8_opt_san/sql/sql_parse.cc:6177:12
          #15 0x559a8a3e3fc7 in mysql_execute_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:3966:12
          #16 0x559a8a3acc92 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_opt_san/sql/sql_parse.cc:7901:18
          #17 0x559a8a3a1b9e in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_opt_san/sql/sql_parse.cc:1903:7
          #18 0x559a8a3afa6e in do_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:1416:17
          #19 0x559a8ab90e38 in do_handle_one_connection(CONNECT*, bool) /test/11.8_opt_san/sql/sql_connect.cc:1415:11
          #20 0x559a8ab90280 in handle_one_connection /test/11.8_opt_san/sql/sql_connect.cc:1327:5
          #21 0x559a89cd8b0c in asan_thread_start(void*) asan_interceptors.cpp.o
          #22 0x145ea4e9ca93 in start_thread nptl/pthread_create.c:447:8
          #23 0x145ea4f29c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: nullptr-with-offset /test/11.8_opt_san/strings/ctype.c:1157:46 
      

      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++' 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'. For an example of UBSAN.filter, which includes current startup issues see: https://github.com/mariadb-corporation/mariadb-qa/blob/master/UBSAN.filter
      

      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.1 (dbg), 11.7.1 (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.