@@ -377,7 +377,7 @@ list_dbs(MYSQL *mysql,const char *wild)
377
377
uint length , counter = 0 ;
378
378
ulong rowcount = 0L ;
379
379
char tables [NAME_LEN + 1 ], rows [NAME_LEN + 1 ];
380
- char query [255 ];
380
+ char query [NAME_LEN + 100 ];
381
381
MYSQL_FIELD * field ;
382
382
MYSQL_RES * result ;
383
383
MYSQL_ROW row = NULL , rrow ;
@@ -444,7 +444,8 @@ list_dbs(MYSQL *mysql,const char *wild)
444
444
MYSQL_ROW trow ;
445
445
while ((trow = mysql_fetch_row (tresult )))
446
446
{
447
- sprintf (query ,"SELECT COUNT(*) FROM `%s`" ,trow [0 ]);
447
+ my_snprintf (query , sizeof (query ),
448
+ "SELECT COUNT(*) FROM `%s`" , trow [0 ]);
448
449
if (!(mysql_query (mysql ,query )))
449
450
{
450
451
MYSQL_RES * rresult ;
@@ -500,7 +501,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
500
501
{
501
502
const char * header ;
502
503
uint head_length , counter = 0 ;
503
- char query [255 ], rows [NAME_LEN ], fields [16 ];
504
+ char query [NAME_LEN + 100 ], rows [NAME_LEN ], fields [16 ];
504
505
MYSQL_FIELD * field ;
505
506
MYSQL_RES * result ;
506
507
MYSQL_ROW row , rrow ;
@@ -585,7 +586,8 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
585
586
if (opt_verbose > 1 )
586
587
{
587
588
/* Print the count of rows for each table */
588
- sprintf (query ,"SELECT COUNT(*) FROM `%s`" ,row [0 ]);
589
+ my_snprintf (query , sizeof (query ), "SELECT COUNT(*) FROM `%s`" ,
590
+ row [0 ]);
589
591
if (!(mysql_query (mysql ,query )))
590
592
{
591
593
if ((rresult = mysql_store_result (mysql )))
@@ -645,13 +647,15 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
645
647
static int
646
648
list_table_status (MYSQL * mysql ,const char * db ,const char * wild )
647
649
{
648
- char query [1024 ],* end ;
650
+ char query [NAME_LEN + 100 ];
651
+ int len ;
649
652
MYSQL_RES * result ;
650
653
MYSQL_ROW row ;
651
654
652
- end = strxmov (query ,"show table status from `" ,db ,"`" ,NullS );
653
- if (wild && wild [0 ])
654
- strxmov (end ," like '" ,wild ,"'" ,NullS );
655
+ len = sizeof (query );
656
+ len -= my_snprintf (query , len , "show table status from `%s`" , db );
657
+ if (wild && wild [0 ] && len )
658
+ strxnmov (query + strlen (query ), len , " like '" , wild , "'" , NullS );
655
659
if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
656
660
{
657
661
fprintf (stderr ,"%s: Cannot get status for db: %s, table: %s: %s\n" ,
@@ -683,7 +687,8 @@ static int
683
687
list_fields (MYSQL * mysql ,const char * db ,const char * table ,
684
688
const char * wild )
685
689
{
686
- char query [1024 ],* end ;
690
+ char query [NAME_LEN + 100 ];
691
+ int len ;
687
692
MYSQL_RES * result ;
688
693
MYSQL_ROW row ;
689
694
ulong UNINIT_VAR (rows );
@@ -697,7 +702,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
697
702
698
703
if (opt_count )
699
704
{
700
- sprintf (query ,"select count(*) from `%s`" , table );
705
+ my_snprintf (query , sizeof ( query ), "select count(*) from `%s`" , table );
701
706
if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
702
707
{
703
708
fprintf (stderr ,"%s: Cannot get record count for db: %s, table: %s: %s\n" ,
@@ -709,9 +714,11 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
709
714
mysql_free_result (result );
710
715
}
711
716
712
- end = strmov (strmov (strmov (query ,"show /*!32332 FULL */ columns from `" ),table ),"`" );
713
- if (wild && wild [0 ])
714
- strxmov (end ," like '" ,wild ,"'" ,NullS );
717
+ len = sizeof (query );
718
+ len -= my_snprintf (query , len , "show /*!32332 FULL */ columns from `%s`" ,
719
+ table );
720
+ if (wild && wild [0 ] && len )
721
+ strxnmov (query + strlen (query ), len , " like '" , wild , "'" , NullS );
715
722
if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
716
723
{
717
724
fprintf (stderr ,"%s: Cannot list columns in db: %s, table: %s: %s\n" ,
@@ -732,7 +739,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
732
739
print_res_top (result );
733
740
if (opt_show_keys )
734
741
{
735
- end = strmov ( strmov ( strmov ( query , "show keys from `" ), table ), "`" );
742
+ my_snprintf ( query , sizeof ( query ), "show keys from `%s`" , table );
736
743
if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
737
744
{
738
745
fprintf (stderr ,"%s: Cannot list keys in db: %s, table: %s: %s\n" ,
0 commit comments