Skip to content

Commit 20addb0

Browse files
committed
Bug# 25998635: Client does not escape the USE statement
When there are quotes in the USE statement, the mysql client does not correctly escape them. The USE statement is processed line by line from the client's parser, and cannot handle multi-line commands as the server. The fix is to escape the USE parameters whenever quotes are used.
1 parent 3b562dc commit 20addb0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

client/mysql.cc

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3386,7 +3386,7 @@ print_table_data(MYSQL_RES *result)
33863386
length=4; // Room for "NULL"
33873387
if (opt_binhex && is_binary_field(field))
33883388
length= 2 + length * 2;
3389-
field->max_length=length;
3389+
field->max_length=(ulong) length;
33903390
separator.fill(separator.length()+length+2,'-');
33913391
separator.append('+');
33923392
}
@@ -3453,7 +3453,7 @@ print_table_data(MYSQL_RES *result)
34533453
many extra padding-characters we should send with the printing function.
34543454
*/
34553455
visible_length= charset_info->cset->numcells(charset_info, buffer, buffer + data_length);
3456-
extra_padding= data_length - visible_length;
3456+
extra_padding= (uint) (data_length - visible_length);
34573457

34583458
if (opt_binhex && is_binary_field(field))
34593459
print_as_hex(PAGER, cur[off], lengths[off], field_max_length);
@@ -4232,10 +4232,9 @@ com_use(String *buffer __attribute__((unused)), char *line)
42324232
bzero(buff, sizeof(buff));
42334233

42344234
/*
4235-
In case number of quotes exceed 2, we try to get
4236-
the normalized db name.
4235+
In case of quotes used, try to get the normalized db name.
42374236
*/
4238-
if (get_quote_count(line) > 2)
4237+
if (get_quote_count(line) > 0)
42394238
{
42404239
if (normalize_dbname(line, buff, sizeof(buff)))
42414240
return put_error(&mysql);
@@ -4453,11 +4452,13 @@ char *get_arg(char *line, my_bool get_next_arg)
44534452
static int
44544453
get_quote_count(const char *line)
44554454
{
4456-
int quote_count;
4457-
const char *ptr= line;
4455+
int quote_count= 0;
4456+
const char *quote= line;
44584457

4459-
for(quote_count= 0; ptr ++ && *ptr; ptr= strpbrk(ptr, "\"\'`"))
4460-
quote_count ++;
4458+
while ((quote= strpbrk(quote, "'`\"")) != NULL) {
4459+
quote_count++;
4460+
quote++;
4461+
}
44614462

44624463
return quote_count;
44634464
}

0 commit comments

Comments
 (0)