Commit fc6eda13 authored by lars@mysql.com's avatar lars@mysql.com

Fixes after Sinisa and Serg comments after push of patch for BUG#9123.

BUG#9123 is solved earlier than this patch though.
parent 0997684f
...@@ -871,8 +871,8 @@ static int dbConnect(char *host, char *user,char *passwd) ...@@ -871,8 +871,8 @@ static int dbConnect(char *host, char *user,char *passwd)
cannot reconnect. cannot reconnect.
*/ */
sock->reconnect= 0; sock->reconnect= 0;
sprintf(buff, "/*!40100 SET @@SQL_MODE='%s' */", my_snprintf(buff, sizeof(buff), "/*!40100 SET @@SQL_MODE='%s' */",
compatible_mode_normal_str); compatible_mode_normal_str);
if (mysql_query_with_error_report(sock, 0, buff)) if (mysql_query_with_error_report(sock, 0, buff))
{ {
mysql_close(sock); mysql_close(sock);
...@@ -1107,8 +1107,9 @@ static uint getTableStructure(char *table, char* db) ...@@ -1107,8 +1107,9 @@ static uint getTableStructure(char *table, char* db)
if (verbose) if (verbose)
fprintf(stderr, "-- Retrieving table structure for table %s...\n", table); fprintf(stderr, "-- Retrieving table structure for table %s...\n", table);
sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", my_snprintf(insert_pat, sizeof(insert_pat),
(opt_quoted || opt_keywords)); "SET OPTION SQL_QUOTE_SHOW_CREATE=%d",
(opt_quoted || opt_keywords));
if (!create_options) if (!create_options)
strmov(strend(insert_pat), "/*!40102 ,SQL_MODE=concat(@@sql_mode, _utf8 ',NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS') */"); strmov(strend(insert_pat), "/*!40102 ,SQL_MODE=concat(@@sql_mode, _utf8 ',NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS') */");
...@@ -1126,7 +1127,7 @@ static uint getTableStructure(char *table, char* db) ...@@ -1126,7 +1127,7 @@ static uint getTableStructure(char *table, char* db)
/* Make an sql-file, if path was given iow. option -T was given */ /* Make an sql-file, if path was given iow. option -T was given */
char buff[20+FN_REFLEN]; char buff[20+FN_REFLEN];
sprintf(buff,"show create table %s", result_table); my_snprintf(buff, sizeof(buff), "show create table %s", result_table);
if (mysql_query_with_error_report(sock, 0, buff)) if (mysql_query_with_error_report(sock, 0, buff))
{ {
safe_exit(EX_MYSQLERR); safe_exit(EX_MYSQLERR);
...@@ -1164,7 +1165,8 @@ static uint getTableStructure(char *table, char* db) ...@@ -1164,7 +1165,8 @@ static uint getTableStructure(char *table, char* db)
check_io(sql_file); check_io(sql_file);
mysql_free_result(tableRes); mysql_free_result(tableRes);
} }
sprintf(insert_pat,"show fields from %s", result_table); my_snprintf(insert_pat, sizeof(insert_pat), "show fields from %s",
result_table);
if (mysql_query_with_error_report(sock, &tableRes, insert_pat)) if (mysql_query_with_error_report(sock, &tableRes, insert_pat))
{ {
if (path) if (path)
...@@ -1174,11 +1176,12 @@ static uint getTableStructure(char *table, char* db) ...@@ -1174,11 +1176,12 @@ static uint getTableStructure(char *table, char* db)
} }
if (cFlag) if (cFlag)
sprintf(insert_pat, "INSERT %sINTO %s (", delayed, opt_quoted_table); my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s (",
delayed, opt_quoted_table);
else else
{ {
sprintf(insert_pat, "INSERT %sINTO %s VALUES ", delayed, my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s VALUES ",
opt_quoted_table); delayed, opt_quoted_table);
if (!extended_insert) if (!extended_insert)
strcat(insert_pat,"("); strcat(insert_pat,"(");
} }
...@@ -1205,7 +1208,8 @@ static uint getTableStructure(char *table, char* db) ...@@ -1205,7 +1208,8 @@ static uint getTableStructure(char *table, char* db)
"%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n", "%s: Warning: Can't set SQL_QUOTE_SHOW_CREATE option (%s)\n",
my_progname, mysql_error(sock)); my_progname, mysql_error(sock));
sprintf(insert_pat,"show fields from %s", result_table); my_snprintf(insert_pat, sizeof(insert_pat), "show fields from %s",
result_table);
if (mysql_query_with_error_report(sock, &tableRes, insert_pat)) if (mysql_query_with_error_report(sock, &tableRes, insert_pat))
{ {
safe_exit(EX_MYSQLERR); safe_exit(EX_MYSQLERR);
...@@ -1240,10 +1244,12 @@ static uint getTableStructure(char *table, char* db) ...@@ -1240,10 +1244,12 @@ static uint getTableStructure(char *table, char* db)
check_io(sql_file); check_io(sql_file);
} }
if (cFlag) if (cFlag)
sprintf(insert_pat, "INSERT %sINTO %s (", delayed, result_table); my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s (",
delayed, result_table);
else else
{ {
sprintf(insert_pat, "INSERT %sINTO %s VALUES ", delayed, result_table); my_snprintf(insert_pat, sizeof(insert_pat), "INSERT %sINTO %s VALUES ",
delayed, result_table);
if (!extended_insert) if (!extended_insert)
strcat(insert_pat,"("); strcat(insert_pat,"(");
} }
...@@ -1300,7 +1306,7 @@ static uint getTableStructure(char *table, char* db) ...@@ -1300,7 +1306,7 @@ static uint getTableStructure(char *table, char* db)
/* Make an sql-file, if path was given iow. option -T was given */ /* Make an sql-file, if path was given iow. option -T was given */
char buff[20+FN_REFLEN]; char buff[20+FN_REFLEN];
uint keynr,primary_key; uint keynr,primary_key;
sprintf(buff,"show keys from %s", result_table); my_snprintf(buff, sizeof(buff), "show keys from %s", result_table);
if (mysql_query_with_error_report(sock, &tableRes, buff)) if (mysql_query_with_error_report(sock, &tableRes, buff))
{ {
if (path) if (path)
...@@ -1370,8 +1376,12 @@ static uint getTableStructure(char *table, char* db) ...@@ -1370,8 +1376,12 @@ static uint getTableStructure(char *table, char* db)
if (create_options) if (create_options)
{ {
char show_name_buff[FN_REFLEN]; char show_name_buff[FN_REFLEN];
sprintf(buff,"show table status like %s",
quote_for_like(table, show_name_buff)); /* Check memory for quote_for_like() */
DBUG_ASSERT(2*sizeof(table) < sizeof(show_name_buff));
my_snprintf(buff, sizeof(buff), "show table status like %s",
quote_for_like(table, show_name_buff));
if (mysql_query_with_error_report(sock, &tableRes, buff)) if (mysql_query_with_error_report(sock, &tableRes, buff))
{ {
if (mysql_errno(sock) != ER_PARSE_ERROR) if (mysql_errno(sock) != ER_PARSE_ERROR)
...@@ -1531,8 +1541,9 @@ static void dumpTable(uint numFields, char *table) ...@@ -1531,8 +1541,9 @@ static void dumpTable(uint numFields, char *table)
my_delete(filename, MYF(0)); /* 'INTO OUTFILE' doesn't work, if my_delete(filename, MYF(0)); /* 'INTO OUTFILE' doesn't work, if
filename wasn't deleted */ filename wasn't deleted */
to_unix_path(filename); to_unix_path(filename);
sprintf(query, "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '%s'", my_snprintf(query, QUERY_LENGTH,
filename); "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '%s'",
filename);
end= strend(query); end= strend(query);
if (fields_terminated || enclosed || opt_enclosed || escaped) if (fields_terminated || enclosed || opt_enclosed || escaped)
...@@ -1544,7 +1555,7 @@ static void dumpTable(uint numFields, char *table) ...@@ -1544,7 +1555,7 @@ static void dumpTable(uint numFields, char *table)
end= add_load_option(end, lines_terminated, " LINES TERMINATED BY"); end= add_load_option(end, lines_terminated, " LINES TERMINATED BY");
*end= '\0'; *end= '\0';
sprintf(buff," FROM %s", result_table); my_snprintf(buff, sizeof(buff), " FROM %s", result_table);
end= strmov(end,buff); end= strmov(end,buff);
if (where || order_by) if (where || order_by)
{ {
...@@ -1572,8 +1583,9 @@ static void dumpTable(uint numFields, char *table) ...@@ -1572,8 +1583,9 @@ static void dumpTable(uint numFields, char *table)
result_table); result_table);
check_io(md_result_file); check_io(md_result_file);
} }
sprintf(query, "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s", my_snprintf(query, QUERY_LENGTH,
result_table); "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s",
result_table);
if (where || order_by) if (where || order_by)
{ {
query = alloc_query_str((ulong) (strlen(query) + 1 + query = alloc_query_str((ulong) (strlen(query) + 1 +
...@@ -1671,8 +1683,9 @@ static void dumpTable(uint numFields, char *table) ...@@ -1671,8 +1683,9 @@ static void dumpTable(uint numFields, char *table)
int is_blob; int is_blob;
if (!(field = mysql_fetch_field(res))) if (!(field = mysql_fetch_field(res)))
{ {
sprintf(query,"%s: Not enough fields from table %s! Aborting.\n", my_snprintf(query, QUERY_LENGTH,
my_progname, result_table); "%s: Not enough fields from table %s! Aborting.\n",
my_progname, result_table);
fputs(query,stderr); fputs(query,stderr);
error= EX_CONSCHECK; error= EX_CONSCHECK;
goto err; goto err;
...@@ -1873,12 +1886,13 @@ static void dumpTable(uint numFields, char *table) ...@@ -1873,12 +1886,13 @@ static void dumpTable(uint numFields, char *table)
check_io(md_result_file); check_io(md_result_file);
if (mysql_errno(sock)) if (mysql_errno(sock))
{ {
sprintf(query,"%s: Error %d: %s when dumping table %s at row: %ld\n", my_snprintf(query, QUERY_LENGTH,
my_progname, "%s: Error %d: %s when dumping table %s at row: %ld\n",
mysql_errno(sock), my_progname,
mysql_error(sock), mysql_errno(sock),
result_table, mysql_error(sock),
rownr); result_table,
rownr);
fputs(query,stderr); fputs(query,stderr);
error= EX_CONSCHECK; error= EX_CONSCHECK;
goto err; goto err;
...@@ -1994,8 +2008,9 @@ static int init_dumping(char *database) ...@@ -1994,8 +2008,9 @@ static int init_dumping(char *database)
MYSQL_ROW row; MYSQL_ROW row;
MYSQL_RES *dbinfo; MYSQL_RES *dbinfo;
sprintf(qbuf,"SHOW CREATE DATABASE IF NOT EXISTS %s", my_snprintf(qbuf, sizeof(qbuf),
qdatabase); "SHOW CREATE DATABASE IF NOT EXISTS %s",
qdatabase);
if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock))) if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock)))
{ {
...@@ -2107,12 +2122,15 @@ static void get_actual_table_name(const char *old_table_name, ...@@ -2107,12 +2122,15 @@ static void get_actual_table_name(const char *old_table_name,
{ {
MYSQL_RES *tableRes; MYSQL_RES *tableRes;
MYSQL_ROW row; MYSQL_ROW row;
char query[2*NAME_LEN+50]; char query[50 + 2*NAME_LEN];
char show_name_buff[FN_REFLEN]; char show_name_buff[FN_REFLEN];
DBUG_ENTER("get_actual_table_name"); DBUG_ENTER("get_actual_table_name");
sprintf(query, "SHOW TABLES LIKE %s", /* Check memory for quote_for_like() */
quote_for_like(old_table_name, show_name_buff)); DBUG_ASSERT(2*sizeof(old_table_name) < sizeof(show_name_buff));
my_snprintf(query, sizeof(query), "SHOW TABLES LIKE %s",
quote_for_like(old_table_name, show_name_buff));
if (mysql_query_with_error_report(sock, 0, query)) if (mysql_query_with_error_report(sock, 0, query))
{ {
safe_exit(EX_MYSQLERR); safe_exit(EX_MYSQLERR);
...@@ -2357,8 +2375,10 @@ static const char *check_if_ignore_table(const char *table_name) ...@@ -2357,8 +2375,10 @@ static const char *check_if_ignore_table(const char *table_name)
MYSQL_ROW row; MYSQL_ROW row;
const char *result= 0; const char *result= 0;
sprintf(buff,"show table status like %s", /* Check memory for quote_for_like() */
quote_for_like(table_name, show_name_buff)); DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff));
my_snprintf(buff, sizeof(buff), "show table status like %s",
quote_for_like(table_name, show_name_buff));
if (mysql_query_with_error_report(sock, &res, buff)) if (mysql_query_with_error_report(sock, &res, buff))
{ {
if (mysql_errno(sock) != ER_PARSE_ERROR) if (mysql_errno(sock) != ER_PARSE_ERROR)
...@@ -2411,7 +2431,8 @@ static char *primary_key_fields(const char *table_name) ...@@ -2411,7 +2431,8 @@ static char *primary_key_fields(const char *table_name)
uint result_length = 0; uint result_length = 0;
char *result = 0; char *result = 0;
sprintf(show_keys_buff, "SHOW KEYS FROM %s", table_name); my_snprintf(show_keys_buff, sizeof(show_keys_buff),
"SHOW KEYS FROM %s", table_name);
if (mysql_query(sock, show_keys_buff) || if (mysql_query(sock, show_keys_buff) ||
!(res = mysql_store_result(sock))) !(res = mysql_store_result(sock)))
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment