MXS-1048: Handle backquoted database names

The schemarouter didn't expect backquoted database names for SHOW TABLE
and USE statements.
This commit is contained in:
Markus Makela
2016-12-13 13:51:46 +02:00
parent ea81990542
commit 3872cebd09
2 changed files with 29 additions and 24 deletions

View File

@ -531,8 +531,9 @@ char* get_shard_target_name(ROUTER_INSTANCE* router,
query = modutil_get_SQL(buffer);
if ((tmp = strcasestr(query, "from")))
{
char *saved, *tok = strtok_r(tmp, " ;", &saved);
tok = strtok_r(NULL, " ;", &saved);
const char *delim = "` \n\t;";
char *saved, *tok = strtok_r(tmp, delim, &saved);
tok = strtok_r(NULL, delim, &saved);
ss_dassert(tok != NULL);
tmp = (char*) hashtable_fetch(ht, tok);

View File

@ -33,8 +33,11 @@ bool extract_database(GWBUF* buf, char* str)
/** Copy database name from MySQL packet to session */
if (qc_get_operation(buf) == QUERY_OP_CHANGE_DB)
{
const char *delim = "` \n\t;";
query = modutil_get_SQL(buf);
tok = strtok_r(query," ;",&saved);
tok = strtok_r(query, delim, &saved);
if (tok == NULL || strcasecmp(tok, "use") != 0)
{
MXS_ERROR("extract_database: Malformed chage database packet.");
@ -42,10 +45,11 @@ bool extract_database(GWBUF* buf, char* str)
goto retblock;
}
tok = strtok_r(NULL," ;",&saved);
tok = strtok_r(NULL, delim, &saved);
if (tok == NULL)
{
MXS_ERROR("extract_database: Malformed chage database packet.");
MXS_ERROR("extract_database: Malformed change database packet.");
succp = false;
goto retblock;
}