Commit c754b00a authored by Jim Winstead's avatar Jim Winstead

The handling of NUL bytes in column data in the various output formats

supported by the mysql client was inconsistent. (Bug #28203)
parent f0f4efd7
...@@ -169,6 +169,8 @@ static const char *xmlmeta[] = { ...@@ -169,6 +169,8 @@ static const char *xmlmeta[] = {
"<", "&lt;", "<", "&lt;",
">", "&gt;", ">", "&gt;",
"\"", "&quot;", "\"", "&quot;",
/* Turn \0 into a space. Why not &#0;? That's not valid XML or HTML. */
"\0", " ",
0, 0 0, 0
}; };
static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; static const char *day_names[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
...@@ -3496,11 +3498,29 @@ print_table_data_vertically(MYSQL_RES *result) ...@@ -3496,11 +3498,29 @@ print_table_data_vertically(MYSQL_RES *result)
mysql_field_seek(result,0); mysql_field_seek(result,0);
tee_fprintf(PAGER, tee_fprintf(PAGER,
"*************************** %d. row ***************************\n", row_count); "*************************** %d. row ***************************\n", row_count);
ulong *lengths= mysql_fetch_lengths(result);
for (uint off=0; off < mysql_num_fields(result); off++) for (uint off=0; off < mysql_num_fields(result); off++)
{ {
field= mysql_fetch_field(result); field= mysql_fetch_field(result);
tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name); tee_fprintf(PAGER, "%*s: ",(int) max_length,field->name);
tee_fprintf(PAGER, "%s\n",cur[off] ? (char*) cur[off] : "NULL"); if (cur[off])
{
unsigned int i;
const char *p;
for (i= 0, p= cur[off]; i < lengths[off]; i+= 1, p+= 1)
{
if (*p == '\0')
tee_putc((int)' ', PAGER);
else
tee_putc((int)*p, PAGER);
}
tee_putc('\n', PAGER);
}
else
tee_fprintf(PAGER, "NULL\n");
} }
} }
} }
...@@ -3567,7 +3587,7 @@ xmlencode_print(const char *src, uint length) ...@@ -3567,7 +3587,7 @@ xmlencode_print(const char *src, uint length)
tee_fputs("NULL", PAGER); tee_fputs("NULL", PAGER);
else else
{ {
for (const char *p = src; *p && length; *p++, length--) for (const char *p = src; length; *p++, length--)
{ {
const char *t; const char *t;
if ((t = array_value(xmlmeta, *p))) if ((t = array_value(xmlmeta, *p)))
...@@ -3587,7 +3607,12 @@ safe_put_field(const char *pos,ulong length) ...@@ -3587,7 +3607,12 @@ safe_put_field(const char *pos,ulong length)
else else
{ {
if (opt_raw_data) if (opt_raw_data)
tee_fputs(pos, PAGER); {
unsigned long i;
/* Can't use tee_fputs(), it stops with NUL characters. */
for (i= 0; i < length; i++, pos++)
tee_putc(*pos, PAGER);
}
else for (const char *end=pos+length ; pos != end ; pos++) else for (const char *end=pos+length ; pos != end ; pos++)
{ {
#ifdef USE_MB #ifdef USE_MB
......
...@@ -162,8 +162,8 @@ ERROR 1049 (42000) at line 1: Unknown database 'invalid' ...@@ -162,8 +162,8 @@ ERROR 1049 (42000) at line 1: Unknown database 'invalid'
ERROR 1049 (42000) at line 1: Unknown database 'invalid' ERROR 1049 (42000) at line 1: Unknown database 'invalid'
Test connect with dbname + hostname Test connect with dbname + hostname
Test connect with dbname + _invalid_ hostname Test connect with dbname + _invalid_ hostname
ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno) ERROR 2003 (HY000) at line 1: Can't connect to MySQL server on 'invalid_hostname' (errno)
ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno) ERROR 2003 (HY000) at line 1: Can't connect to MySQL server on 'invalid_hostname' (errno)
The commands reported in the bug report The commands reported in the bug report
ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno) ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno)
Too long dbname Too long dbname
...@@ -200,5 +200,27 @@ Warning (Code 1286): Unknown table engine 'nonexistent2' ...@@ -200,5 +200,27 @@ Warning (Code 1286): Unknown table engine 'nonexistent2'
Warning (Code 1266): Using storage engine MyISAM for table 't2' Warning (Code 1266): Using storage engine MyISAM for table 't2'
Error (Code 1050): Table 't2' already exists Error (Code 1050): Table 't2' already exists
drop tables t1, t2; drop tables t1, t2;
<TABLE BORDER=1><TR><TH>&lt;</TH></TR><TR><TD>&lt; &amp; &gt;</TD></TR></TABLE> <TABLE BORDER=1><TR><TH>&lt;</TH></TR><TR><TD>&lt; &amp; &gt;</TD></TR></TABLE>create table t1 (a char(5));
insert into t1 values ('\0b\0');
a
\0b\0
a
\0b\0
+------+
| a |
+------+
| b |
+------+
*************************** 1. row ***************************
a: b
<TABLE BORDER=1><TR><TH>a</TH></TR><TR><TD> b </TD></TR></TABLE><?xml version="1.0"?>
<resultset statement="select a from t1
" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<row>
<field name="a"> b </field>
</row>
</resultset>
drop table t1;
End of tests End of tests
...@@ -372,5 +372,19 @@ drop tables t1, t2; ...@@ -372,5 +372,19 @@ drop tables t1, t2;
# #
--exec $MYSQL --html test -e "select '< & >' as \`<\`" --exec $MYSQL --html test -e "select '< & >' as \`<\`"
#
# Bug #27884: mysql client + null byte
#
create table t1 (a char(5));
insert into t1 values ('\0b\0');
--exec $MYSQL test -e "select a from t1"
--exec $MYSQL -r test -e "select a from t1"
--exec $MYSQL -s test -e "select a from t1"
--exec $MYSQL --table test -e "select a from t1"
--exec $MYSQL --vertical test -e "select a from t1"
--exec $MYSQL --html test -e "select a from t1"
--exec $MYSQL --xml test -e "select a from t1"
drop table t1;
--echo --echo
--echo End of tests --echo End of tests
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment