MXS-1628: Fix default database extraction

The default database was not extracted correctly as the length of the
user's name did not include the null terminator. Also the comparison for
database name length used the smaller than operator instead of the correct
larger than operator.
This commit is contained in:
Markus Mäkelä
2018-05-15 11:11:22 +03:00
parent 4e6184c894
commit 3e0a0988f0

View File

@ -601,11 +601,16 @@ static void store_client_information(DCB *dcb, GWBUF *buffer)
const char* username = (const char*)data + MYSQL_AUTH_PACKET_BASE_SIZE;
int userlen = get_zstr_len(username, len - MYSQL_AUTH_PACKET_BASE_SIZE);
if (userlen != -1 && (int)sizeof(ses->user) > userlen)
if (userlen != -1)
{
if ((int)sizeof(ses->user) > userlen)
{
strcpy(ses->user, username);
}
// Include the null terminator in the user length
userlen++;
if (proto->client_capabilities & GW_MYSQL_CAPABILITIES_CONNECT_WITH_DB)
{
/** Client is connecting with a default database */
@ -616,13 +621,14 @@ static void store_client_information(DCB *dcb, GWBUF *buffer)
{
int dblen = get_zstr_len((const char*)data + dboffset, len - dboffset);
if (dblen != -1 && (int)sizeof(ses->db) < dblen)
if (dblen != -1 && (int)sizeof(ses->db) > dblen)
{
strcpy(ses->db, (const char*)data + dboffset);
}
}
}
}
}
}
/**