Skip to content

Commit

Permalink
Fix and testcase of the bug, that was found during investigation on
Browse files Browse the repository at this point in the history
ODBC-109. It's not clear atm if the bug causes the reported error in the
connector's work, since I can't reproduce the bug. But looks probable.
For the info type SQL_SCHEMA_TERM/SQL_OWNER_TERM the connector returned
wrong length. Or more exactly - did not write anything into application's length buffer
  • Loading branch information
lawrinn committed Feb 1, 2018
1 parent d4d8c72 commit d506530
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
6 changes: 5 additions & 1 deletion ma_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1605,9 +1605,13 @@ SQLRETURN MADB_DbcGetInfo(MADB_Dbc *Dbc, SQLUSMALLINT InfoType, SQLPOINTER InfoV
return Dbc->Error.ReturnValue;
}
if (isWChar && SLen)
{
SLen*= sizeof(SQLWCHAR);
if (StringLengthPtr && SLen)
}
if (IsString_GetInfo_Type(InfoType) && StringLengthPtr)
{
*StringLengthPtr= SLen;
}

return SQL_SUCCESS;
}
Expand Down
54 changes: 46 additions & 8 deletions test/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ ODBC_TEST(test_need_long_data_len)

/* https://jira.mariadb.org/browse/ODBC-61
Request of SQL_FILE_USAGE info crashes connector */
ODBC_TEST(t_odbc61)
ODBC_TEST(odbc61)
{
SQLUSMALLINT info= 0xef;

Expand All @@ -502,7 +502,7 @@ ODBC_TEST(t_odbc61)
Bug ODBC-84 and ODBC-62. For ODBC-84 we only tested, that SQLGetTypeInfo returns something for WCHAR types
For ODBC-62 we need to check CREATE_PARAMS
*/
ODBC_TEST(t_odbc84_62)
ODBC_TEST(odbc84_62)
{
SQLHANDLE henv1;
SQLHANDLE Connection1;
Expand Down Expand Up @@ -637,7 +637,7 @@ ODBC_TEST(t_odbc84_62)
}

/* Test for part of problems causing ODBC-71. Other part is tested in desc.c:t_set_explicit_copy*/
ODBC_TEST(t_odbc71)
ODBC_TEST(odbc71)
{
SQLINTEGER Info;

Expand All @@ -662,7 +662,7 @@ ODBC_TEST(t_odbc71)
/* ODBC-123 Test for SQL_CATALOG_LOCATION info type. The connector incorrectly wrote to the buffer SQLUINTEGER,
while it has to be SQLUSMALLINT,
Also testing SQL_GROUP_BY, which has the same problem */
ODBC_TEST(t_odbc123)
ODBC_TEST(odbc123)
{
SQLUSMALLINT Info;

Expand All @@ -676,6 +676,43 @@ ODBC_TEST(t_odbc123)
}


/* ODBC-109 It's not clear atm if that is the reason behind the report, but it was found during work on this bug.
For the info type SQL_SCHEMA_TERM/SQL_OWNER_TERM the connector returned wrong length. Or more exactly - did not
write anything into application's length buffer */
ODBC_TEST(odbc109)
{
SQLCHAR tn;
SQLSMALLINT StrLen;
SQLHANDLE henv1;
SQLHANDLE Connection1;
SQLCHAR conn[512];

/* SQL_OWNER_TERM is the same as SQL_SCHEMA_TERM */
CHECK_DBC_RC(Connection, SQLGetInfo(Connection, SQL_OWNER_TERM, NULL, 0, &StrLen));
is_num(StrLen, 0);
CHECK_DBC_RC(Connection, SQLGetInfo(Connection, SQL_OWNER_TERM, &tn, 1, NULL));
is_num(tn, 0);

/* odbc 2 */
sprintf((char *)conn, "DRIVER=%s;SERVER=%s;UID=%s;PASSWORD=%s;PORT=%d",
my_drivername, my_servername, my_uid, my_pwd, my_port);

CHECK_ENV_RC(henv1, SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv1));
CHECK_ENV_RC(henv1, SQLSetEnvAttr(henv1, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER)SQL_OV_ODBC2, SQL_IS_INTEGER));
CHECK_ENV_RC(henv1, SQLAllocHandle(SQL_HANDLE_DBC, henv1, &Connection1));
CHECK_DBC_RC(Connection1, SQLDriverConnect(Connection1, NULL, conn, (SQLSMALLINT)strlen(conn), NULL, 0,
NULL, SQL_DRIVER_NOPROMPT));

CHECK_DBC_RC(Connection1, SQLGetInfo(Connection1, SQL_OWNER_TERM, NULL, 0, &StrLen));
is_num(StrLen, 0);
CHECK_DBC_RC(Connection1, SQLGetInfo(Connection1, SQL_OWNER_TERM, &tn, 1, NULL));
is_num(tn, 0);

return OK;
}


MA_ODBC_TESTS my_tests[]=
{
{ t_gettypeinfo, "t_gettypeinfo", NORMAL },
Expand All @@ -692,10 +729,11 @@ MA_ODBC_TESTS my_tests[]=
{ t_bug11749093, "t_bug11749093", NORMAL },
{ bug_odbc15, "odbc15", NORMAL },
{ test_need_long_data_len, "test_need_long_data_len", NORMAL },
{ t_odbc61, "odbc61_SQL_FILE_USAGE", NORMAL },
{ t_odbc84_62, "odbc84_WCHAR_types_odbc62_CREATE_PARAMS", NORMAL },
{ t_odbc71, "odbc71_some_odbc2_types", NORMAL },
{ t_odbc123, "odbc123_catalog_start", NORMAL },
{ odbc61, "odbc61_SQL_FILE_USAGE", NORMAL },
{ odbc84_62, "odbc84_WCHAR_types_odbc62_CREATE_PARAMS", NORMAL },
{ odbc71, "odbc71_some_odbc2_types", NORMAL },
{ odbc123, "odbc123_catalog_start", NORMAL },
{ odbc109, "odbc109_shema_owner_term", NORMAL },
{ NULL, NULL }
};

Expand Down

0 comments on commit d506530

Please sign in to comment.