=== modified file 'ChangeLog' --- ChangeLog 2013-03-20 10:13:21 +0000 +++ ChangeLog 2013-03-21 11:12:31 +0000 @@ -12,6 +12,7 @@ (Bug# 11766369/59469) * Added CLEARTEXT authentication connection option ENABLE_CLEARTEXT_PLUGIN. (Bug#16445091) + * Crash in SQLSetConnectAttr(SQL_ATTR_CURRENT_CATALOG) (Bug# 16526604/63844) ---- === modified file 'driver/ansi.c' --- driver/ansi.c 2012-09-03 22:38:46 +0000 +++ driver/ansi.c 2013-03-21 11:10:43 +0000 @@ -563,7 +563,13 @@ SQLINTEGER len= SQL_NTS; uint errors; - if (dbc->ansi_charset_info->number != dbc->cxn_charset_info->number) + /* + When SQLGetConnectAttr is called before connecting + dbc->ansi_charset_info and dbc->cxn_charset_info will be NULL, + so we can just copy the char_value as is. + */ + if (dbc->ansi_charset_info && dbc->ansi_charset_info && + dbc->ansi_charset_info->number != dbc->cxn_charset_info->number) { char_value= sqlchar_as_sqlchar(dbc->cxn_charset_info, dbc->ansi_charset_info, === modified file 'driver/unicode.c' --- driver/unicode.c 2012-12-13 23:31:25 +0000 +++ driver/unicode.c 2013-03-21 09:19:02 +0000 @@ -428,8 +428,20 @@ SQLWCHAR *wvalue; SQLINTEGER len= SQL_NTS; uint errors; - - wvalue= sqlchar_as_sqlwchar(dbc->cxn_charset_info, char_value, + CHARSET_INFO *result_charset_info= dbc->cxn_charset_info; + + /* + When SQLGetConnectAttr is called before connecting the connection + is not established yet and its charset is unknown. We assume UTF8 + as the most suitable charset for the string result. + */ + if(!dbc->cxn_charset_info) + { + result_charset_info= get_charset_by_csname("utf8", MYF(MY_CS_PRIMARY), + MYF(0)); + } + + wvalue= sqlchar_as_sqlwchar(result_charset_info, char_value, &len, &errors); /* value_max is in bytes, we want it in chars. */ === modified file 'test/my_basics.c' --- test/my_basics.c 2013-03-07 11:57:40 +0000 +++ test/my_basics.c 2013-03-21 11:22:10 +0000 @@ -1001,8 +1001,8 @@ DECLARE_BASIC_HANDLES(henv1, hdbc1, hstmt1); SQLCHAR buff1[512], buff2[512]; - sprintf((char *)buff1, "{asd}", myuid); - sprintf((char *)buff2, " 1%s ", mypwd); + sprintf((char *)buff1, " {%s} ", myuid); + sprintf((char *)buff2, " %s ", mypwd); is(OK == alloc_basic_handles_with_opt(&henv1, &hdbc1, &hstmt1, NULL, buff1, buff2, NULL, NULL)); @@ -1012,6 +1012,33 @@ } +/* + Bug#45378 - Crash in SQLSetConnectAttr +*/ +DECLARE_TEST(t_bug63844) +{ + SQLHDBC hdbc1; + SQLCHAR *DatabaseName = mydb; + + /* + We are not going to use alloc_basic_handles() for a special purpose: + SQLSetConnectAttr() is to be called before the connection is made + */ + ok_env(henv, SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1)); + + ok_con(hdbc1, SQLSetConnectAttr(hdbc1, SQL_ATTR_CURRENT_CATALOG, + DatabaseName, strlen(DatabaseName))); + + /* The driver crashes here on getting connected */ + ok_con(hdbc1, get_connection(&hdbc1, NULL, NULL, NULL, NULL, NULL)); + + ok_con(hdbc1, SQLDisconnect(hdbc1)); + ok_con(hdbc1, SQLFreeConnect(hdbc1)); + + return OK; +} + + BEGIN_TESTS ADD_TEST(my_basics) ADD_TEST(t_max_select) @@ -1040,6 +1067,7 @@ ADD_TEST(t_bug44971) ADD_TEST(t_bug48603) ADD_TEST(t_bug45378) + ADD_TEST(t_bug63844) END_TESTS