Bug #46858 Not using "thr_lock_data_init" in the plugin let the serve crash.
Submitted: 21 Aug 2009 14:29 Modified: 7 Sep 2009 10:08
Reporter: Horst Hunger Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Storage Engine API Severity:S2 (Serious)
Version:5.1, azalea OS:Linux
Assigned to: CPU Architecture:Any

[21 Aug 2009 14:29] Horst Hunger
Description:
the following trace back shows what happens if the pugin doesn't use the function  "thr_lock_data_init". The server shouldn't get corrupted in that case, because for a plugin developer it is not obvious that the plugin init is not complete.
the trace back:

Program terminated with signal 11, Segmentation fault.
#0  0xffffe410 in __kernel_vsyscall ()
#0  0xffffe410 in __kernel_vsyscall ()
#1  0xb7f71397 in pthread_kill () from /lib/libpthread.so.0
#2  0x0852f4ab in my_write_core (sig=11) at stacktrace.c:309
#3  0x081fb0ac in handle_segfault (sig=141119476) at mysqld.cc:2718
#4  <signal handler called>
#5  0x08533873 in safe_mutex_lock (mp=0xc, my_flags=0, file=0x867f832 "thr_lock.c", line=555)
    at thr_mutex.c:170
#6  0x08531f44 in thr_lock (data=0x895799c, owner=0x89b5368, lock_type=TL_WRITE_CONCURRENT_INSERT)
    at thr_lock.c:555
#7  0x085323a1 in thr_multi_lock (data=0x88f1d6c, count=1, owner=0x89b5368) at thr_lock.c:1020
#8  0x081f3c5f in mysql_lock_tables (thd=0x89b4b40, tables=0x89140e0, count=1,
    flags=<value optimized out>, need_reopen=0xb73ae7bb) at lock.cc:321
#9  0x0824f854 in lock_tables (thd=0x89b4b40, tables=0x8913bb0, count=1, flags=0,
    need_reopen=0xb73ae7bb) at sql_base.cc:4541
#10 0x0825a877 in open_and_lock_tables_derived (thd=0x89b4b40, tables=0x8913bb0,
    derived=<value optimized out>, flags=0) at sql_base.cc:4235
#11 0x0829c5b5 in mysql_insert (thd=0x89b4b40, table_list=0x8913bb0, fields=@0x89b6020,
    values_list=@0x89b6044, update_fields=@0x89b6038, update_values=@0x89b602c, duplic=DUP_ERROR,
    ignore=false) at mysql_priv.h:1519
#12 0x0820eb64 in mysql_execute_command (thd=0x89b4b40) at sql_parse.cc:3220
#13 0x08212c39 in mysql_parse (thd=0x89b4b40,
    inBuf=0x89138d8 "INSERT INTO t1 VALUES (\"qwertz\",1)", length=34, found_semicolon=0xb73aff00)
    at sql_parse.cc:5942
#14 0x0821444f in dispatch_command (command=COM_QUERY, thd=0x89b4b40,
    packet=0x88ec439 "INSERT INTO t1 VALUES (\"qwertz\",1)", packet_length=34) at sql_parse.cc:1061
#15 0x08214ce8 in do_command (thd=0x89b4b40) at sql_parse.cc:743
#16 0x08203857 in handle_one_connection (arg=0x89b4b40) at sql_connect.cc:1158
#17 0xb7f6c192 in start_thread () from /lib/libpthread.so.0
#18 0xb7d8a02e in clone () from /lib/libc.so.6

How to repeat:
Use mysql-azalea-wl4939. Go into storage/tse and comment out line 169 in ha_tse.cc (  thr_lock_data_init(&f_lock, &lock, (void*) this);). After a make run the test tse_insert_simple.

Suggested fix:
React with an error or implement default values for the lock, which might be used if the init will not be done by the plugin. Don't forget to describe it.
[21 Aug 2009 14:31] Horst Hunger
see also bug#46851.
[25 Aug 2009 20:00] Sveta Smirnova
Thank you for the report.

Verified as described.
[1 Sep 2009 19:48] Sveta Smirnova
Same problem exists in 5.1

To repeat: modify CSV engine as described, then modify test tse_insert_simple as follows and run it:

$cat t/bug46858.test 
# Test of storage engine TSE as plugin.
#
# Creation:
# 2009-08-04 Hunger
#
#INSTALL PLUGIN tse SONAME 'ha_tse.so';
CREATE TABLE t1 (c1 char(20) not null, c2 int not null) ENGINE csv;
INSERT INTO t1 VALUES ("qwertz",1);
INSERT INTO t1 VALUES ("asdfgh",2);
INSERT INTO t1 VALUES ("yxcvbn",3);
INSERT INTO t1 VALUES ("QWERTZ",4);
INSERT INTO t1 VALUES ("ASDFGH",5);
INSERT INTO t1 VALUES ("YXCVBN",6);
INSERT INTO t1 VALUES ("poiuzt",7);
INSERT INTO t1 VALUES ("lkjhgf",8);
INSERT INTO t1 VALUES ("mnbvcx",9);
INSERT INTO t1 VALUES ("zbdtzhfghjuzttgfghzu",10);
#UNINSTALL PLUGIN tse ;

$cat t/bug46858-master.opt 
--log-output=FILE
[8 Nov 2010 15:05] MySQL Verification Team
is this bug present in any unmodified released version of mysql ?
[11 Nov 2010 12:00] Sergey Vojtovich
Not using thr_lock_data_init, but further returning uninitialized THR_LOCK_DATA is definitely violation of thr_lock API. Suggested status: not a bug.