@@ -400,7 +400,7 @@ list_dbs(MYSQL *mysql,const char *wild)
400
400
uint length , counter = 0 ;
401
401
ulong rowcount = 0L ;
402
402
char tables [NAME_LEN + 1 ], rows [NAME_LEN + 1 ];
403
- char query [255 ];
403
+ char query [NAME_LEN + 100 ];
404
404
MYSQL_FIELD * field ;
405
405
MYSQL_RES * result ;
406
406
MYSQL_ROW row = NULL , rrow ;
@@ -467,7 +467,8 @@ list_dbs(MYSQL *mysql,const char *wild)
467
467
MYSQL_ROW trow ;
468
468
while ((trow = mysql_fetch_row (tresult )))
469
469
{
470
- sprintf (query ,"SELECT COUNT(*) FROM `%s`" ,trow [0 ]);
470
+ my_snprintf (query , sizeof (query ),
471
+ "SELECT COUNT(*) FROM `%s`" , trow [0 ]);
471
472
if (!(mysql_query (mysql ,query )))
472
473
{
473
474
MYSQL_RES * rresult ;
@@ -523,7 +524,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
523
524
{
524
525
const char * header ;
525
526
uint head_length , counter = 0 ;
526
- char query [255 ], rows [NAME_LEN ], fields [16 ];
527
+ char query [NAME_LEN + 100 ], rows [NAME_LEN ], fields [16 ];
527
528
MYSQL_FIELD * field ;
528
529
MYSQL_RES * result ;
529
530
MYSQL_ROW row , rrow ;
@@ -608,7 +609,8 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
608
609
if (opt_verbose > 1 )
609
610
{
610
611
/* Print the count of rows for each table */
611
- sprintf (query ,"SELECT COUNT(*) FROM `%s`" ,row [0 ]);
612
+ my_snprintf (query , sizeof (query ), "SELECT COUNT(*) FROM `%s`" ,
613
+ row [0 ]);
612
614
if (!(mysql_query (mysql ,query )))
613
615
{
614
616
if ((rresult = mysql_store_result (mysql )))
@@ -668,13 +670,15 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
668
670
static int
669
671
list_table_status (MYSQL * mysql ,const char * db ,const char * wild )
670
672
{
671
- char query [1024 ],* end ;
673
+ char query [NAME_LEN + 100 ];
674
+ int len ;
672
675
MYSQL_RES * result ;
673
676
MYSQL_ROW row ;
674
677
675
- end = strxmov (query ,"show table status from `" ,db ,"`" ,NullS );
676
- if (wild && wild [0 ])
677
- strxmov (end ," like '" ,wild ,"'" ,NullS );
678
+ len = sizeof (query );
679
+ len -= my_snprintf (query , len , "show table status from `%s`" , db );
680
+ if (wild && wild [0 ] && len )
681
+ strxnmov (query + strlen (query ), len , " like '" , wild , "'" , NullS );
678
682
if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
679
683
{
680
684
fprintf (stderr ,"%s: Cannot get status for db: %s, table: %s: %s\n" ,
@@ -706,7 +710,8 @@ static int
706
710
list_fields (MYSQL * mysql ,const char * db ,const char * table ,
707
711
const char * wild )
708
712
{
709
- char query [1024 ],* end ;
713
+ char query [NAME_LEN + 100 ];
714
+ int len ;
710
715
MYSQL_RES * result ;
711
716
MYSQL_ROW row ;
712
717
ulong UNINIT_VAR (rows );
@@ -720,7 +725,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
720
725
721
726
if (opt_count )
722
727
{
723
- sprintf (query ,"select count(*) from `%s`" , table );
728
+ my_snprintf (query , sizeof ( query ), "select count(*) from `%s`" , table );
724
729
if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
725
730
{
726
731
fprintf (stderr ,"%s: Cannot get record count for db: %s, table: %s: %s\n" ,
@@ -732,9 +737,11 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
732
737
mysql_free_result (result );
733
738
}
734
739
735
- end = strmov (strmov (strmov (query ,"show /*!32332 FULL */ columns from `" ),table ),"`" );
736
- if (wild && wild [0 ])
737
- strxmov (end ," like '" ,wild ,"'" ,NullS );
740
+ len = sizeof (query );
741
+ len -= my_snprintf (query , len , "show /*!32332 FULL */ columns from `%s`" ,
742
+ table );
743
+ if (wild && wild [0 ] && len )
744
+ strxnmov (query + strlen (query ), len , " like '" , wild , "'" , NullS );
738
745
if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
739
746
{
740
747
fprintf (stderr ,"%s: Cannot list columns in db: %s, table: %s: %s\n" ,
@@ -755,7 +762,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
755
762
print_res_top (result );
756
763
if (opt_show_keys )
757
764
{
758
- end = strmov ( strmov ( strmov ( query , "show keys from `" ), table ), "`" );
765
+ my_snprintf ( query , sizeof ( query ), "show keys from `%s`" , table );
759
766
if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
760
767
{
761
768
fprintf (stderr ,"%s: Cannot list keys in db: %s, table: %s: %s\n" ,
0 commit comments