[MDEV-9414] Crash with ConnectSE + MySQL ODBC driver + discovery Created: 2016-01-14  Updated: 2017-11-05

Status: Open
Project: MariaDB Server
Component/s: Storage Engine - Connect
Affects Version/s: 10.1
Fix Version/s: 10.1

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Olivier Bertrand
Resolution: Unresolved Votes: 2
Labels: None

Issue Links:
Relates
relates to MDEV-9380 MariaDB server crashes with CONNECT e... Open

 Description   

I create a table on the remote 10.0.21-MariaDB server:

CREATE OR REPLACE TABLE t1 (a INT);
INSERT INTO t1 VALUES (10),(20),(30);

Now connect the remote table to a local 10.1.10-MariaDB-debug server:

CREATE OR REPLACE TABLE t1 (a int) ENGINE=CONNECT TABLE_TYPE=ODBC  CONNECTION='dsn=MySQL;uid=root';
SELECT * FROM t1;

This seems to work fine.

Now I additionally use automatic table structure discovery:

CREATE OR REPLACE TABLE t1 ENGINE=CONNECT TABLE_TYPE=ODBC CONNECTION='dsn=MySQL;uid=root';

It crashes with this stack trace:

#0  0x0000000000000000 in ?? ()
#1  0x00007fff896b35bb in mysql_list_fields ()
   from /usr/lib64/mysql/libmysqlclient.so.18
#2  0x00007fffa8dba72c in server_list_dbcolumns ()
   from /usr/lib64/libmyodbc5.so
#3  0x00007fffa8dbad46 in columns_no_i_s () from /usr/lib64/libmyodbc5.so
#4  0x00007fffa8dd9465 in SQLColumnsW () from /usr/lib64/libmyodbc5.so
#5  0x00007fffb259e4a3 in SQLColumns () from /lib64/libodbc.so.2
#6  0x00007ffff35afd13 in ODBConn::GetCatInfo (this=0x7fff89c00048, 
    cap=0x7fff89cf9d08)
    at /home/bar/maria-git/server.10.1/storage/connect/odbconn.cpp:2261
#7  0x00007ffff35ab9bd in ODBCColumns (g=0x7fff8e833000, 
    dsn=0x7fff89c00008 "dsn=MySQL;uid=root", db=0x0, 
    table=0x7fff8e8251b0 "t1", colpat=0x0, maxres=4096, info=false, 
    sop=0x7fff89c00020)
    at /home/bar/maria-git/server.10.1/storage/connect/odbconn.cpp:380
#8  0x00007ffff34f3187 in connect_assisted_discovery (thd=0x7fff9fa29070, 
    table_s=0x7ffff7f7dc30, create_info=0x7ffff7f7e8c0)
...

   │2256    //                                (SQLPOINTER)true, 0);            │
   │2257            fnc = "SQLColumns";                                        │
   │2258            rc = SQLColumns(hstmt, name.ptr(2), name.length(2),        │
   │2259                                   name.ptr(1), name.length(1),        │
   │2260                                   name.ptr(0), name.length(0),        │
  >│2261                                   cap->Pat, SQL_NTS);  

cap->Pat is NULL here, which looks wrong in combination with SQL_NTS.
It should be either NULL + 0, or an empty string "" + SQL_NTS.

But changing the code like this did not really help:

index 1ccdf23..b196d3f 100644
--- a/storage/connect/odbconn.cpp
+++ b/storage/connect/odbconn.cpp
@@ -2258,7 +2258,7 @@ int ODBConn::GetCatInfo(CATPARM *cap)
         rc = SQLColumns(hstmt, name.ptr(2), name.length(2),
                                name.ptr(1), name.length(1),
                                name.ptr(0), name.length(0),
-                               cap->Pat, SQL_NTS);
+                               cap->Pat, cap->Pat ? SQL_NTS : 0);
         break;
       case CAT_KEY:
         fnc = "SQLPrimaryKeys";

Neither helped this:

--- a/storage/connect/odbconn.cpp
+++ b/storage/connect/odbconn.cpp
@@ -2258,7 +2258,8 @@ int ODBConn::GetCatInfo(CATPARM *cap)
         rc = SQLColumns(hstmt, name.ptr(2), name.length(2),
                                name.ptr(1), name.length(1),
                                name.ptr(0), name.length(0),
-                               cap->Pat, SQL_NTS);
+                               cap->Pat ? cap->Pat : (unsigned char*) "",
+                               cap->Pat ? SQL_NTS : 0);
         break;
       case CAT_KEY:
         fnc = "SQLPrimaryKeys";

So the reason must be somewhere else.



 Comments   
Comment by Olivier Bertrand [ 2016-01-14 ]

Alexander, which connector are you using?
Using the MySQL ODBC connector version 5.3 I cannot reproduce the crash on Windows 7.
BTW your fix cap->Pat, cap->Pat ? SQL_NTS : 0); seems correct but the actual code has been used for many years and apparently did not cause any problem yet.

Comment by Alexander Barkov [ 2016-01-14 ]

I'm using mysql-connector-odbc-5.3.4-4.fc23.x86_64,
which is the part of Fedora 23 distribution.

Yeah, the problem must be somewhere else. The patch does not help indeed.
But anyway, please consider adding this patch, as using NULL with SQL_NTS looks dangerous.

Comment by Olivier Bertrand [ 2016-01-14 ]

This is the same connector I am using except that it is the Windows version.
Perhaps it is a problem with unixODBC.

Generated at Thu Feb 08 07:34:29 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.