Index: ChangeLog =================================================================== --- ChangeLog (revision 736) +++ ChangeLog (working copy) @@ -3,6 +3,8 @@ Functionality added or changed: Bugs fixed: + * The specified length of the username and authentication parameters to + SQLConnect() were not being honored. (Bug #30774) * SQLGetData() will now always return SQL_NO_DATA_FOUND on second call when no data left, even if requested size is 0. (Bug#30520) * SQLSetParam() caused memory allocation errors due to driver manager's Index: driver/connect.c =================================================================== --- driver/connect.c (revision 736) +++ driver/connect.c (working copy) @@ -316,9 +316,17 @@ /* Set username and password if they were provided. */ if (szUID && szUID[0]) - ds->pszUSER= _global_strdup((char *)szUID); + { + if (cbUID == SQL_NTS) + cbUID= strlen((char *)szUID); + ds->pszUSER= _global_strndup((char *)szUID, cbUID); + } if (szAuth && szAuth[0]) - ds->pszPASSWORD= _global_strdup((char *)szAuth); + { + if (cbAuth == SQL_NTS) + cbAuth= strlen((char *)szAuth); + ds->pszPASSWORD= _global_strndup((char *)szAuth, cbAuth); + } /* We don't care if this fails, because we might be able to get away Index: test/my_basics.c =================================================================== --- test/my_basics.c (revision 736) +++ test/my_basics.c (working copy) @@ -416,6 +416,41 @@ } +/** + Bug #30774: Username argument to SQLConnect used incorrectly +*/ +DECLARE_TEST(t_bug30774) +{ + SQLHDBC hdbc1; + SQLHSTMT hstmt1; + SQLCHAR username[80]= {0}; + + strcat((char *)username, (char *)myuid); + strcat((char *)username, "!!!"); + + ok_env(henv, SQLAllocConnect(henv, &hdbc1)); + ok_con(hdbc1, SQLConnect(hdbc1, mydsn, SQL_NTS, + username, strlen((char *)myuid), + mypwd, SQL_NTS)); + ok_con(hdbc1, SQLAllocStmt(hdbc1, &hstmt1)); + + ok_sql(hstmt1, "SELECT USER()"); + ok_stmt(hstmt1, SQLFetch(hstmt1)); + my_fetch_str(hstmt1, username, 1); + printMessage("username: %s", username); + is(!strstr((char *)username, "!!!")); + + expect_stmt(hstmt1, SQLFetch(hstmt1), SQL_NO_DATA_FOUND); + + ok_stmt(hstmt1, SQLFreeStmt(hstmt1, SQL_DROP)); + + ok_con(hdbc1, SQLDisconnect(hdbc1)); + ok_con(hdbc1, SQLFreeConnect(hdbc1)); + + return OK; +} + + BEGIN_TESTS ADD_TEST(my_basics) ADD_TEST(t_max_select) @@ -428,6 +463,7 @@ ADD_TEST(charset_utf8) ADD_TEST(charset_gbk) ADD_TEST(t_bug7445) + ADD_TEST(t_bug30774) END_TESTS