@@ -1347,7 +1347,9 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
1347
1347
{
1348
1348
uchar * pos ;
1349
1349
/* fields count may be wrong */
1350
- DBUG_ASSERT ((uint ) (field - result ) < fields );
1350
+ if (field - result >= fields )
1351
+ goto err ;
1352
+
1351
1353
cli_fetch_lengths (& lengths [0 ], row -> data , default_value ? 8 : 7 );
1352
1354
field -> catalog = strmake_root (alloc ,(char * ) row -> data [0 ], lengths [0 ]);
1353
1355
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,
1365
1367
1366
1368
/* Unpack fixed length parts */
1367
1369
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 ;
1374
1371
1375
1372
pos = (uchar * ) row -> data [6 ];
1376
1373
field -> charsetnr = uint2korr (pos );
@@ -1397,6 +1394,8 @@ unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
1397
1394
/* old protocol, for backward compatibility */
1398
1395
for (row = data -> data ; row ; row = row -> next ,field ++ )
1399
1396
{
1397
+ if (field - result >= fields )
1398
+ goto err ;
1400
1399
cli_fetch_lengths (& lengths [0 ], row -> data , default_value ? 6 : 5 );
1401
1400
field -> org_table = field -> table = strdup_root (alloc ,(char * ) row -> data [0 ]);
1402
1401
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,
1433
1432
}
1434
1433
}
1435
1434
#endif /* DELETE_SUPPORT_OF_4_0_PROTOCOL */
1435
+ if (field - result < fields )
1436
+ goto err ;
1436
1437
free_rows (data ); /* Free old data */
1437
1438
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 );
1438
1446
}
1439
1447
1440
1448
/* Read all rows (fields or data) from server */
0 commit comments