summaryrefslogtreecommitdiff
path: root/sql-common
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2020-05-05 21:16:22 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2020-05-05 21:16:22 +0300
commit7bcaa541aa1f298abf8e863566a19b3e9ec2f659 (patch)
tree066d58ad89536edf0e9a3de898506735c933381f /sql-common
parent36b8ac2c0d763a3f96b254cb6e2cbdbc40dde22b (diff)
parent2c3c851d2cba73825f81cd06220138b15c17ae4d (diff)
downloadmariadb-git-7bcaa541aa1f298abf8e863566a19b3e9ec2f659.tar.gz
Merge 10.4 into 10.5
Diffstat (limited to 'sql-common')
-rw-r--r--sql-common/client.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/sql-common/client.c b/sql-common/client.c
index ee3ec65a233..1ce80a17d24 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1188,9 +1188,23 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
{
if (field >= result + fields)
goto err;
+
+ /*
+ If any of the row->data[] below is NULL, it can result in a
+ crash. Error out early as it indicates a malformed packet.
+ For data[0], data[1] and data[5], strmake_root will handle
+ NULL values.
+ */
+ if (!row->data[2] || !row->data[3] || !row->data[4])
+ {
+ free_rows(data);
+ set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
+ DBUG_RETURN(0);
+ }
+
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]);
+ field->org_table= field->table= strmake_root(alloc,(char*) row->data[0], lengths[0]);
+ field->name= strmake_root(alloc,(char*) row->data[1], lengths[1]);
field->length= (uint) uint3korr(row->data[2]);
field->type= (enum enum_field_types) (uchar) row->data[3][0];
@@ -1215,7 +1229,7 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
field->flags|= NUM_FLAG;
if (default_value && row->data[5])
{
- field->def=strdup_root(alloc,(char*) row->data[5]);
+ field->def= strmake_root(alloc,(char*) row->data[5], lengths[5]);
field->def_length= lengths[5];
}
else