@@ -400,7 +400,7 @@ list_dbs(MYSQL *mysql,const char *wild)
400400 uint length , counter = 0 ;
401401 ulong rowcount = 0L ;
402402 char tables [NAME_LEN + 1 ], rows [NAME_LEN + 1 ];
403- char query [255 ];
403+ char query [NAME_LEN + 100 ];
404404 MYSQL_FIELD * field ;
405405 MYSQL_RES * result ;
406406 MYSQL_ROW row = NULL , rrow ;
@@ -467,7 +467,8 @@ list_dbs(MYSQL *mysql,const char *wild)
467467 MYSQL_ROW trow ;
468468 while ((trow = mysql_fetch_row (tresult )))
469469 {
470- sprintf (query ,"SELECT COUNT(*) FROM `%s`" ,trow [0 ]);
470+ my_snprintf (query , sizeof (query ),
471+ "SELECT COUNT(*) FROM `%s`" , trow [0 ]);
471472 if (!(mysql_query (mysql ,query )))
472473 {
473474 MYSQL_RES * rresult ;
@@ -523,7 +524,7 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
523524{
524525 const char * header ;
525526 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 ];
527528 MYSQL_FIELD * field ;
528529 MYSQL_RES * result ;
529530 MYSQL_ROW row , rrow ;
@@ -608,7 +609,8 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
608609 if (opt_verbose > 1 )
609610 {
610611 /* 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 ]);
612614 if (!(mysql_query (mysql ,query )))
613615 {
614616 if ((rresult = mysql_store_result (mysql )))
@@ -668,13 +670,15 @@ list_tables(MYSQL *mysql,const char *db,const char *table)
668670static int
669671list_table_status (MYSQL * mysql ,const char * db ,const char * wild )
670672{
671- char query [1024 ],* end ;
673+ char query [NAME_LEN + 100 ];
674+ int len ;
672675 MYSQL_RES * result ;
673676 MYSQL_ROW row ;
674677
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 );
678682 if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
679683 {
680684 fprintf (stderr ,"%s: Cannot get status for db: %s, table: %s: %s\n" ,
@@ -706,7 +710,8 @@ static int
706710list_fields (MYSQL * mysql ,const char * db ,const char * table ,
707711 const char * wild )
708712{
709- char query [1024 ],* end ;
713+ char query [NAME_LEN + 100 ];
714+ int len ;
710715 MYSQL_RES * result ;
711716 MYSQL_ROW row ;
712717 ulong UNINIT_VAR (rows );
@@ -720,7 +725,7 @@ list_fields(MYSQL *mysql,const char *db,const char *table,
720725
721726 if (opt_count )
722727 {
723- sprintf (query ,"select count(*) from `%s`" , table );
728+ my_snprintf (query , sizeof ( query ), "select count(*) from `%s`" , table );
724729 if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
725730 {
726731 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,
732737 mysql_free_result (result );
733738 }
734739
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 );
738745 if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
739746 {
740747 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,
755762 print_res_top (result );
756763 if (opt_show_keys )
757764 {
758- end = strmov ( strmov ( strmov ( query , "show keys from `" ), table ), "`" );
765+ my_snprintf ( query , sizeof ( query ), "show keys from `%s`" , table );
759766 if (mysql_query (mysql ,query ) || !(result = mysql_store_result (mysql )))
760767 {
761768 fprintf (stderr ,"%s: Cannot list keys in db: %s, table: %s: %s\n" ,
0 commit comments