summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2018-05-04 00:09:45 +0200
committerSergei Golubchik <serg@mariadb.org>2018-05-04 14:40:19 +0200
commit1d58d184c2c4ddd8a3b2be6f86d76c4e57bbe14f (patch)
treeab9a4f892ff53f3931518989e492f719c4cfc7f1 /sql-common
parentfab383aac0a713b48765d0464428199470ae8c0a (diff)
downloadmariadb-git-1d58d184c2c4ddd8a3b2be6f86d76c4e57bbe14f.tar.gz
protocol: verify that number of rows is correct
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/client.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/sql-common/client.c b/sql-common/client.c
index 00e2877bedb..6321e64bc75 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1483,7 +1483,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]);
@@ -1501,12 +1503,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);
@@ -1533,6 +1530,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]);
@@ -1569,8 +1568,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 */