Skip to content

Commit 3c07ed1

Browse files
committed
Merge branch '5.5' into 10.0
2 parents 04b1e61 + 1d58d18 commit 3c07ed1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

sql-common/client.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,9 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
13471347
{
13481348
uchar *pos;
13491349
/* fields count may be wrong */
1350-
DBUG_ASSERT((uint) (field - result) < fields);
1350+
if (field - result >= fields)
1351+
goto err;
1352+
13511353
cli_fetch_lengths(&lengths[0], row->data, default_value ? 8 : 7);
13521354
field->catalog= strmake_root(alloc,(char*) row->data[0], lengths[0]);
13531355
field->db= strmake_root(alloc,(char*) row->data[1], lengths[1]);
@@ -1365,12 +1367,7 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
13651367

13661368
/* Unpack fixed length parts */
13671369
if (lengths[6] != 12)
1368-
{
1369-
/* malformed packet. signal an error. */
1370-
free_rows(data); /* Free old data */
1371-
set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
1372-
DBUG_RETURN(0);
1373-
}
1370+
goto err;
13741371

13751372
pos= (uchar*) row->data[6];
13761373
field->charsetnr= uint2korr(pos);
@@ -1397,6 +1394,8 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
13971394
/* old protocol, for backward compatibility */
13981395
for (row=data->data; row ; row = row->next,field++)
13991396
{
1397+
if (field - result >= fields)
1398+
goto err;
14001399
cli_fetch_lengths(&lengths[0], row->data, default_value ? 6 : 5);
14011400
field->org_table= field->table= strdup_root(alloc,(char*) row->data[0]);
14021401
field->name= strdup_root(alloc,(char*) row->data[1]);
@@ -1433,8 +1432,17 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
14331432
}
14341433
}
14351434
#endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */
1435+
if (field - result < fields)
1436+
goto err;
14361437
free_rows(data); /* Free old data */
14371438
DBUG_RETURN(result);
1439+
1440+
err:
1441+
/* malformed packet. signal an error. */
1442+
free_rows(data);
1443+
free_root(alloc, MYF(0));
1444+
set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
1445+
DBUG_RETURN(0);
14381446
}
14391447

14401448
/* Read all rows (fields or data) from server */

0 commit comments

Comments
 (0)