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

UBSAN: runtime error: applying zero offset to null pointer in my_convert_using_func on INSERT

    XMLWordPrintable

Details

    Description

      SET sql_mode='';
      CREATE TABLE t (c SET('','') KEY);
      INSERT INTO t VALUES (0),(0);
      

      Leads to:

      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 0x55e00d6d14a6 in my_convert_using_func /test/11.8_opt_san/strings/ctype.c:1157:46
          #1 0x55e00a85fedc in err_conv(char*, unsigned int, char const*, unsigned int, charset_info_st const*) /test/11.8_opt_san/sql/sql_error.cc:956:10
          #2 0x55e00a52ebbd in ErrBuff::set_str(char const*, unsigned long, charset_info_st const*) const /test/11.8_opt_san/sql/sql_error.h:875:10
          #3 0x55e00a52ebbd in ErrConvString::lex_cstring() const /test/11.8_opt_san/sql/sql_error.h:922:12
          #4 0x55e00c1df221 in field_unpack(String*, Field*, unsigned char const*, unsigned int, bool) /test/11.8_opt_san/sql/key.cc:396:20
          #5 0x55e00c1dfcaf in key_unpack(String*, TABLE*, st_key*) /test/11.8_opt_san/sql/key.cc:441:5
          #6 0x55e00bb52408 in print_keydup_error(TABLE*, st_key*, char const*, unsigned long) /test/11.8_opt_san/sql/handler.cc:4657:5
          #7 0x55e00bb546a5 in handler::print_error(int, unsigned long) /test/11.8_opt_san/sql/handler.cc:4762:9
          #8 0x55e00a890c61 in write_record(THD*, TABLE*, st_copy_info*, select_result*) /test/11.8_opt_san/sql/sql_insert.cc:2363:16
          #9 0x55e00a87c086 in mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item>>&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) /test/11.8_opt_san/sql/sql_insert.cc:1181:14
          #10 0x55e00aa49a2a in mysql_execute_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:4471:10
          #11 0x55e00aa09c92 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_opt_san/sql/sql_parse.cc:7901:18
          #12 0x55e00a9feb9e in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_opt_san/sql/sql_parse.cc:1903:7
          #13 0x55e00aa0ca6e in do_command(THD*, bool) /test/11.8_opt_san/sql/sql_parse.cc:1416:17
          #14 0x55e00b1ede38 in do_handle_one_connection(CONNECT*, bool) /test/11.8_opt_san/sql/sql_connect.cc:1415:11
          #15 0x55e00b1ed280 in handle_one_connection /test/11.8_opt_san/sql/sql_connect.cc:1327:5
          #16 0x55e00a335b0c in asan_thread_start(void*) asan_interceptors.cpp.o
          #17 0x1459a649ca93 in start_thread nptl/pthread_create.c:447:8
          #18 0x1459a6529c3b 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 
      

      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 0x56291f9d27aa in my_convert_using_func /test/11.8_dbg_san/strings/ctype.c:1157:46
          #1 0x562919214c7b in err_conv(char*, unsigned int, char const*, unsigned int, charset_info_st const*) /test/11.8_dbg_san/sql/sql_error.cc:956:10
          #2 0x562918b027f2 in ErrBuff::set_str(char const*, unsigned long, charset_info_st const*) const /test/11.8_dbg_san/sql/sql_error.h:875:10
          #3 0x562918b0247e in ErrConvString::lex_cstring() const /test/11.8_dbg_san/sql/sql_error.h:922:12
          #4 0x56291c7068f1 in field_unpack(String*, Field*, unsigned char const*, unsigned int, bool) /test/11.8_dbg_san/sql/key.cc:396:20
          #5 0x56291c707e73 in key_unpack(String*, TABLE*, st_key*) /test/11.8_dbg_san/sql/key.cc:441:5
          #6 0x56291bb8b62f in print_keydup_error(TABLE*, st_key*, char const*, unsigned long) /test/11.8_dbg_san/sql/handler.cc:4657:5
          #7 0x56291bb8c0c7 in print_keydup_error(TABLE*, st_key*, unsigned long) /test/11.8_dbg_san/sql/handler.cc:4680:3
          #8 0x56291bb8dac3 in handler::print_error(int, unsigned long) /test/11.8_dbg_san/sql/handler.cc:4762:9
          #9 0x562919285ce3 in write_record(THD*, TABLE*, st_copy_info*, select_result*) /test/11.8_dbg_san/sql/sql_insert.cc:2363:16
          #10 0x56291924b830 in mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item>>&, List<Item>&, List<Item>&, enum_duplicates, bool, select_result*) /test/11.8_dbg_san/sql/sql_insert.cc:1181:14
          #11 0x5629195bf907 in mysql_execute_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:4471:10
          #12 0x562919555ef9 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.8_dbg_san/sql/sql_parse.cc:7901:18
          #13 0x562919536db8 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1903:7
          #14 0x56291955fe56 in do_command(THD*, bool) /test/11.8_dbg_san/sql/sql_parse.cc:1416:17
          #15 0x56291a6c2556 in do_handle_one_connection(CONNECT*, bool) /test/11.8_dbg_san/sql/sql_connect.cc:1415:11
          #16 0x56291a6c0d19 in handle_one_connection /test/11.8_dbg_san/sql/sql_connect.cc:1327:5
          #17 0x5629187095fc in asan_thread_start(void*) asan_interceptors.cpp.o
          #18 0x15405909ca93 in start_thread nptl/pthread_create.c:447:8
          #19 0x154059129c3b 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 
      

      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.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)

      Bug (or feature/syntax) confirmed not present in:
      MariaDB: 10.5.28 (dbg), 10.5.28 (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.