Source: mariadb-connector-c Source-Version: 2.3.2-2 Severity: serious Tags: patch
Hi! While packaging the mariadb-connector-odbc for internal use, we started to notice crashes in asterisk due to the ODBC asterisk plugin. The problem ended up being an abort initiated by the internal Dbug code within mariadb-connector-c's libmariadb.a that the mariadb-connector-odbc statically links against. Skimming over the code revealed that there's at least one function with an unbalanced DBUG_RETURN(), but even after patching that the plugin was still crashing. Checking the latest mariadb-connector-c upstream shows that the Dbug support has been completely removed there, so instead of trying to track it down, followed the same path. Our asterisk instance using its odbc plugin that uses mariadb-connector-odbc is working fine now. I think this is serious enough that it should be fixed in a stable update. Here's an example backtrace of such crashes: ,--- Core was generated by `/usr/sbin/asterisk -p -g -U asterisk'. Program terminated with signal SIGABRT, Aborted. #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51 51 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory. [Current thread is 1 (Thread 0x7f454b05b700 (LWP 19858))] (gdb) bt full #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51 set = {__val = {0, 94034738822584, 139935588123936, 5655481737, 94034738821728, 139935588123920, 139935689551805, 252833149, 4294967295, 0, 139937266863576, 139937324438456, 0, 0, 8227920807149371393, 7814153793824583285}} pid = <optimized out> tid = <optimized out> #1 0x00007f45af17e3fa in __GI_abort () at abort.c:89 save_stage = 2 act = {__sigaction_handler = {sa_handler = 0x424420676e697373, sa_sigaction = 0x424420676e697373}, sa_mask = {__val = { 5932740740841949013, 266287972354, 139937080938440, 139935588124576, 139935689985411, 0, 2, 139935588124976, 139935689791148, 0, 2880, 0, 139937270617936, 139937270613280, 139937270617936, 139935588136704}}, sa_flags = -1357180916, sa_restorer = 0x55862994d2c0 <stderr>} sigs = {__val = {32, 0 <repeats 15 times>}} #2 0x00007f455112ba21 in DbugExit () from /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so No symbol table info available. #3 0x00007f45511508b5 in _db_return_ () from /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so No symbol table info available. #4 0x00007f4551157dbe in mysql_reconnect () from /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so No symbol table info available. #5 0x00007f455115800d in mthd_my_send_cmd () from /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so No symbol table info available. #6 0x00007f4551154570 in mysql_ping () from /usr/lib/x86_64-linux-gnu/odbc/libmaodbc.so No symbol table info available. #7 0x00007f4551138638 in MADB_DbcGetAttr (Dbc=0x55862b3464b0, Attribute=1209, ValuePtr=0x7f454b0591d8, BufferLength=0, StringLengthPtr=0x0, isWChar=<optimized out>) at ./ma_connection.c:309 No locals. #8 0x00007f45511313b4 in MA_SQLGetConnectAttr ( ConnectionHandle=0x55862b3464b0, Attribute=1209, ValuePtr=0x7f454b0591d8, BufferLength=0, StringLengthPtr=0x0) at ./odbc_3_api.c:1660 Dbc = 0x55862b3464b0 ret = <optimized out> `--- And attached the patch we ended up using. Although just forcing -DDBUG_OFF would be enough. Thanks, Guillem
Description: Fix crashes due to internal Dbug support The mysql_ping() function is using an unbalanced DBUG_ENTER() on entry, but not DBUG_RETURN() on return, which means that the stack frame that is being checked in _db_return_ will get out of sync, and eventually it will abort the plugin. . Although this fix is not enough and the library keeps crashing. Instead follow a similar route upstream has taken in git master (removing the Dbug support) by completely disabling its support. Origin: other, Sipwise Author: Guillem Jover <gjo...@sipwise.com> Last-Update: 2017-10-18 --- --- CMakeLists.txt | 2 ++ libmariadb/libmariadb.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) --- a/libmariadb/libmariadb.c +++ b/libmariadb/libmariadb.c @@ -2903,7 +2903,7 @@ mysql_ping(MYSQL *mysql) /* if connection was terminated and reconnect is true, try again */ if (rc!=0 && mysql->reconnect) rc= simple_command(mysql,MYSQL_COM_PING,0,0,0,0); - return rc; + DBUG_RETURN(rc); } --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,8 @@ SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLA SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DDBUG_OFF") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -DDBUG_OFF") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -DDBUG_OFF") +# XXX: Disable dbug information for all builds, it causes crashes. +ADD_DEFINITIONS(-DDBUG_OFF) IF(CMAKE_COMPILER_IS_GNUCC) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wno-uninitialized")