summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2018-05-11 13:12:18 +0200
committerSergei Golubchik <serg@mariadb.org>2018-05-11 13:15:10 +0200
commitc9717dc0190731c656cce31fa6e39a3db123e3af (patch)
tree3db056a3f50e565294d127edb5339afb0a994749 /sql-common
parent33721d91389759a917463a044fbd6f0b7654d629 (diff)
parent1d411a8a440922f0538c1be254d6f4396af453a1 (diff)
downloadmariadb-git-c9717dc0190731c656cce31fa6e39a3db123e3af.tar.gz
Merge branch '10.2' into 10.3
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/client.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/sql-common/client.c b/sql-common/client.c
index bed41ab1015..aee3852eea5 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1343,7 +1343,9 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
{
uchar *pos;
/* fields count may be wrong */
- DBUG_ASSERT((uint) (field - result) < fields);
+ if (field >= result + fields)
+ goto err;
+
cli_fetch_lengths(&lengths[0], row->data, default_value ? 8 : 7);
field->catalog= strmake_root(alloc,(char*) row->data[0], lengths[0]);
field->db= strmake_root(alloc,(char*) row->data[1], lengths[1]);
@@ -1361,12 +1363,7 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
/* Unpack fixed length parts */
if (lengths[6] != 12)
- {
- /* malformed packet. signal an error. */
- free_rows(data); /* Free old data */
- set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
- DBUG_RETURN(0);
- }
+ goto err;
pos= (uchar*) row->data[6];
field->charsetnr= uint2korr(pos);
@@ -1393,6 +1390,8 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
/* old protocol, for backward compatibility */
for (row=data->data; row ; row = row->next,field++)
{
+ if (field >= result + fields)
+ goto err;
cli_fetch_lengths(&lengths[0], row->data, default_value ? 6 : 5);
field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]);
field->name= strdup_root(alloc,(char*) row->data[1]);
@@ -1429,8 +1428,17 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
}
}
#endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */
+ if (field < result + fields)
+ goto err;
free_rows(data); /* Free old data */
DBUG_RETURN(result);
+
+err:
+ /* malformed packet. signal an error. */
+ free_rows(data);
+ free_root(alloc, MYF(0));
+ set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
+ DBUG_RETURN(0);
}
/* Read all rows (fields or data) from server */
@@ -1499,7 +1507,7 @@ MYSQL_DATA *cli_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields,
else
{
cur->data[field] = to;
- if (len > (ulong) (end_to - to))
+ if (unlikely(len > (ulong)(end_to-to) || to > end_to))
{
free_rows(result);
set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
@@ -1571,7 +1579,7 @@ read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths)
}
else
{
- if (pos + len > end_pos)
+ if (unlikely(len > (ulong)(end_pos - pos) || pos > end_pos))
{
set_mysql_error(mysql, CR_UNKNOWN_ERROR, unknown_sqlstate);
return -1;
@@ -2732,7 +2740,7 @@ static int client_mpvio_read_packet(struct st_plugin_vio *mpv, uchar **buf)
*buf= mysql->net.read_pos;
/* was it a request to change plugins ? */
- if (**buf == 254)
+ if (pkt_len == packet_error || **buf == 254)
return (int)packet_error; /* if yes, this plugin shan't continue */
/*
@@ -2917,7 +2925,7 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
compile_time_assert(CR_OK == -1);
compile_time_assert(CR_ERROR == 0);
- if (res > CR_OK && mysql->net.read_pos[0] != 254)
+ if (res > CR_OK && (mysql->net.last_errno || mysql->net.read_pos[0] != 254))
{
/*
the plugin returned an error. write it down in mysql,