[MDEV-16810] AddressSanitizer: stack-buffer-overflow in int10_to_str Created: 2018-07-24  Updated: 2018-08-11  Resolved: 2018-08-11

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3
Fix Version/s: 5.5.62, 10.0.37, 10.1.36, 10.2.18, 10.3.10

Type: Bug Priority: Major
Reporter: Alice Sherepa Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: None


 Description   

CREATE TABLE t1 (v2 varchar(35)) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('Rae Bareli');
 
SELECT PERIOD_DIFF('2018-07-24', (AES_ENCRYPT(v2, v2))) FROM t1;

=================================================================
==18339==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7feeddbeb6d4 at pc 0x5587b0e7ec11 bp 0x7feeddbeb590 sp 0x7feeddbeb580
WRITE of size 1 at 0x7feeddbeb6d4 thread T27
    #0 0x5587b0e7ec10 in int10_to_str /git/10.3/strings/int2str.c:174
    #1 0x5587af1ba12b in Protocol_text::store_long(long long) /git/10.3/sql/protocol.cc:1171
    #2 0x5587af86dc2b in Type_handler::Item_send_long(Item*, Protocol*, st_value*) const /git/10.3/sql/sql_type.cc:5306
    #3 0x5587af874f75 in Type_handler_long::Item_send(Item*, Protocol*, st_value*) const (/git/10.3/sql/mysqld+0x147bf75)
    #4 0x5587af1c42bf in Item::send(Protocol*, st_value*) /git/10.3/sql/item.h:877
    #5 0x5587af1b7fe9 in Protocol::send_result_set_row(List<Item>*) /git/10.3/sql/protocol.cc:986
    #6 0x5587af321379 in select_send::send_data(List<Item>&) /git/10.3/sql/sql_class.cc:2932
    #7 0x5587af51eb50 in end_send /git/10.3/sql/sql_select.cc:20451
    #8 0x5587af51764b in evaluate_join_record /git/10.3/sql/sql_select.cc:19491
    #9 0x5587af51624f in sub_select(JOIN*, st_join_table*, bool) /git/10.3/sql/sql_select.cc:19271
    #10 0x5587af5146ee in do_select /git/10.3/sql/sql_select.cc:18811
    #11 0x5587af4b4016 in JOIN::exec_inner() /git/10.3/sql/sql_select.cc:4021
    #12 0x5587af4b1d5b in JOIN::exec() /git/10.3/sql/sql_select.cc:3815
    #13 0x5587af4b512d 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*) /git/10.3/sql/sql_select.cc:4220
    #14 0x5587af490972 in handle_select(THD*, LEX*, select_result*, unsigned long) /git/10.3/sql/sql_select.cc:382
    #15 0x5587af4164c3 in execute_sqlcom_select /git/10.3/sql/sql_parse.cc:6542
    #16 0x5587af404cd6 in mysql_execute_command(THD*) /git/10.3/sql/sql_parse.cc:3765
    #17 0x5587af41edd1 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /git/10.3/sql/sql_parse.cc:8073
    #18 0x5587af3f9ab8 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /git/10.3/sql/sql_parse.cc:1847
    #19 0x5587af3f6c50 in do_command(THD*) /git/10.3/sql/sql_parse.cc:1392
    #20 0x5587af7460b5 in do_handle_one_connection(CONNECT*) /git/10.3/sql/sql_connect.cc:1402
    #21 0x5587af745a92 in handle_one_connection /git/10.3/sql/sql_connect.cc:1308
    #22 0x5587b0c842e2 in pfs_spawn_thread /git/10.3/storage/perfschema/pfs.cc:1862
    #23 0x7feef6f296b9 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76b9)
    #24 0x7feef63be41c in clone (/lib/x86_64-linux-gnu/libc.so.6+0x10741c)
 
Address 0x7feeddbeb6d4 is located in stack of thread T27 at offset 52 in frame
    #0 0x5587af1b9d97 in Protocol_text::store_long(long long) /git/10.3/sql/protocol.cc:1162
 
  This frame has 1 object(s):
    [32, 52) 'buff' <== Memory access at offset 52 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext
      (longjmp and C++ exceptions *are* supported)
Thread T27 created by T0 here:
    #0 0x7feef8687253 in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x36253)
    #1 0x5587b0c846cf in spawn_thread_v1 /git/10.3/storage/perfschema/pfs.cc:1912
    #2 0x5587af179a44 in inline_mysql_thread_create /git/10.3/include/mysql/psi/mysql_thread.h:1268
    #3 0x5587af18edc3 in create_thread_to_handle_connection(CONNECT*) /git/10.3/sql/mysqld.cc:6557
    #4 0x5587af18f4c3 in create_new_thread /git/10.3/sql/mysqld.cc:6627
    #5 0x5587af190500 in handle_connections_sockets() /git/10.3/sql/mysqld.cc:6902
    #6 0x5587af18e283 in mysqld_main(int, char**) /git/10.3/sql/mysqld.cc:6179
    #7 0x5587af17816f in main /git/10.3/sql/main.cc:25
    #8 0x7feef62d782f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
 
SUMMARY: AddressSanitizer: stack-buffer-overflow /git/10.3/strings/int2str.c:174 int10_to_str
Shadow bytes around the buggy address:
  0x0ffe5bb75680: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffe5bb75690: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffe5bb756a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffe5bb756b0: 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 00 00
  0x0ffe5bb756c0: 00 00 00 00 00 00 01 f4 f4 f4 f3 f3 f3 f3 00 00
=>0x0ffe5bb756d0: 00 00 00 00 f1 f1 f1 f1 00 00[04]f4 f3 f3 f3 f3
  0x0ffe5bb756e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffe5bb756f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffe5bb75700: f1 f1 f1 f1 00 00 00 00 f2 f2 f2 f2 00 00 00 00
  0x0ffe5bb75710: f2 f2 f2 f2 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ffe5bb75720: 00 00 00 00 00 00 00 00 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
  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
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
==18339==ABORTING
----------SERVER LOG END-------------


Generated at Thu Feb 08 08:31:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.