Skip to content

Commit

Permalink
Merge branch 'mysql-5.5' into mysql-5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Shishir Jaiswal committed May 16, 2016
2 parents 4cd5282 + cb29741 commit ab3d743
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 58 deletions.
2 changes: 1 addition & 1 deletion client/mysqladmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv)

int offset= sprintf(buffer, "ALTER USER USER() IDENTIFIED BY '");
int length= (int)mysql_real_escape_string(mysql, buffer + offset,
typed_password,
typed_password, (ulong)
strlen(typed_password));
if (length == -1)
{
Expand Down
42 changes: 26 additions & 16 deletions client/mysqlcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ static int process_selected_tables(char *db, char **table_names, int tables);
static int process_all_tables_in_db(char *database);
static int process_one_db(char *database);
static int use_db(char *database);
static int handle_request_for_tables(char *tables, uint length);
static int handle_request_for_tables(char *tables, size_t length);
static int dbConnect(char *host, char *user,char *passwd);
static void dbDisconnect(char *host);
static void DBerror(MYSQL *mysql, const char *when);
static void safe_exit(int error);
static void print_result();
static uint fixed_name_length(const char *name);
static size_t fixed_name_length(const char *name);
static char *fix_table_name(char *dest, char *src);
int what_to_do = 0;

Expand Down Expand Up @@ -501,7 +501,7 @@ static int process_selected_tables(char *db, char **table_names, int tables)
*end++= ',';
}
*--end = 0;
handle_request_for_tables(table_names_comma_sep + 1, (uint) (tot_length - 1));
handle_request_for_tables(table_names_comma_sep + 1, tot_length - 1);
my_free(table_names_comma_sep);
}
else
Expand All @@ -511,10 +511,10 @@ static int process_selected_tables(char *db, char **table_names, int tables)
} /* process_selected_tables */


static uint fixed_name_length(const char *name)
static size_t fixed_name_length(const char *name)
{
const char *p;
uint extra_length= 2; /* count the first/last backticks */
size_t extra_length= 2; /* count the first/last backticks */

for (p= name; *p; p++)
{
Expand All @@ -523,7 +523,7 @@ static uint fixed_name_length(const char *name)
else if (*p == '.')
extra_length+= 2;
}
return (uint) ((p - name) + extra_length);
return (size_t) ((p - name) + extra_length);
}


Expand Down Expand Up @@ -579,7 +579,7 @@ static int process_all_tables_in_db(char *database)
*/

char *tables, *end;
uint tot_length = 0;
size_t tot_length = 0;

while ((row = mysql_fetch_row(res)))
tot_length+= fixed_name_length(row[0]) + 2;
Expand Down Expand Up @@ -637,7 +637,9 @@ static int fix_table_storage_name(const char *name)
int rc= 0;
if (strncmp(name, "#mysql50#", 9))
return 1;
sprintf(qbuf, "RENAME TABLE `%s` TO `%s`", name, name + 9);
my_snprintf(qbuf, sizeof(qbuf), "RENAME TABLE `%s` TO `%s`",
name, name + 9);

rc= run_query(qbuf);
if (verbose)
printf("%-50s %s\n", name, rc ? "FAILED" : "OK");
Expand All @@ -650,7 +652,8 @@ static int fix_database_storage_name(const char *name)
int rc= 0;
if (strncmp(name, "#mysql50#", 9))
return 1;
sprintf(qbuf, "ALTER DATABASE `%s` UPGRADE DATA DIRECTORY NAME", name);
my_snprintf(qbuf, sizeof(qbuf), "ALTER DATABASE `%s` UPGRADE DATA DIRECTORY "
"NAME", name);
rc= run_query(qbuf);
if (verbose)
printf("%-50s %s\n", name, rc ? "FAILED" : "OK");
Expand All @@ -668,7 +671,7 @@ static int rebuild_table(char *name)
ptr= strmov(query, "ALTER TABLE ");
ptr= fix_table_name(ptr, name);
ptr= strxmov(ptr, " FORCE", NullS);
if (mysql_real_query(sock, query, (uint)(ptr - query)))
if (mysql_real_query(sock, query, (ulong)(ptr - query)))
{
fprintf(stderr, "Failed to %s\n", query);
fprintf(stderr, "Error: %s\n", mysql_error(sock));
Expand Down Expand Up @@ -721,10 +724,10 @@ static int disable_binlog()
return run_query(stmt);
}

static int handle_request_for_tables(char *tables, uint length)
static int handle_request_for_tables(char *tables, size_t length)
{
char *query, *end, options[100], message[100];
uint query_length= 0;
size_t query_length= 0, query_size= sizeof(char)*(length+110);
const char *op = 0;

options[0] = 0;
Expand Down Expand Up @@ -755,10 +758,14 @@ static int handle_request_for_tables(char *tables, uint length)
return fix_table_storage_name(tables);
}

if (!(query =(char *) my_malloc((sizeof(char)*(length+110)), MYF(MY_WME))))
if (!(query =(char *) my_malloc(query_size, MYF(MY_WME))))
{
return 1;
}
if (opt_all_in_1)
{
DBUG_ASSERT(strlen(op)+strlen(tables)+strlen(options)+8+1 <= query_size);

/* No backticks here as we added them before */
query_length= sprintf(query, "%s TABLE %s %s", op, tables, options);
}
Expand All @@ -769,7 +776,7 @@ static int handle_request_for_tables(char *tables, uint length)
ptr= strmov(strmov(query, op), " TABLE ");
ptr= fix_table_name(ptr, tables);
ptr= strxmov(ptr, " ", options, NullS);
query_length= (uint) (ptr - query);
query_length= (size_t) (ptr - query);
}
if (mysql_real_query(sock, query, query_length))
{
Expand Down Expand Up @@ -853,7 +860,10 @@ static void print_result()
prev_alter[0]= 0;
}
else
strcpy(prev_alter, alter_txt);
{
strncpy(prev_alter, alter_txt, MAX_ALTER_STR_SIZE-1);
prev_alter[MAX_ALTER_STR_SIZE-1]= 0;
}
}
}
}
Expand Down Expand Up @@ -1008,7 +1018,7 @@ int main(int argc, char **argv)
process_databases(argv);
if (opt_auto_repair)
{
uint i;
size_t i;

if (!opt_silent && (tables4repair.elements || tables4rebuild.elements))
puts("\nRepairing tables");
Expand Down
49 changes: 27 additions & 22 deletions client/mysqldump.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

static void add_load_option(DYNAMIC_STRING *str, const char *option,
const char *option_value);
static ulong find_set(TYPELIB *lib, const char *x, uint length,
static ulong find_set(TYPELIB *lib, const char *x, size_t length,
char **err_pos, uint *err_len);
static char *alloc_query_str(ulong size);

Expand Down Expand Up @@ -885,7 +885,7 @@ get_one_option(int optid, const struct my_option *opt MY_ATTRIBUTE((unused)),
opt_set_charset= 0;
opt_compatible_mode_str= argument;
opt_compatible_mode= find_set(&compatible_mode_typelib,
argument, (uint) strlen(argument),
argument, strlen(argument),
&err_ptr, &err_len);
if (err_len)
{
Expand All @@ -895,7 +895,7 @@ get_one_option(int optid, const struct my_option *opt MY_ATTRIBUTE((unused)),
}
#if !defined(DBUG_OFF)
{
uint size_for_sql_mode= 0;
size_t size_for_sql_mode= 0;
const char **ptr;
for (ptr= compatible_mode_names; *ptr; ptr++)
size_for_sql_mode+= strlen(*ptr);
Expand Down Expand Up @@ -1182,8 +1182,8 @@ static int fetch_db_collation(const char *db_name,
break;
}

strncpy(db_cl_name, db_cl_row[0], db_cl_size);
db_cl_name[db_cl_size - 1]= 0; /* just in case. */
strncpy(db_cl_name, db_cl_row[0], db_cl_size-1);
db_cl_name[db_cl_size - 1]= 0;

} while (FALSE);

Expand All @@ -1194,7 +1194,7 @@ static int fetch_db_collation(const char *db_name,


static char *my_case_str(const char *str,
uint str_len,
size_t str_len,
const char *token,
uint token_len)
{
Expand Down Expand Up @@ -1410,7 +1410,7 @@ static int switch_character_set_results(MYSQL *mysql, const char *cs_name)
*/

static char *cover_definer_clause(const char *stmt_str,
uint stmt_length,
size_t stmt_length,
const char *definer_version_str,
uint definer_version_length,
const char *stmt_version_str,
Expand Down Expand Up @@ -1603,14 +1603,14 @@ static void dbDisconnect(char *host)
} /* dbDisconnect */


static void unescape(FILE *file,char *pos,uint length)
static void unescape(FILE *file,char *pos, size_t length)
{
char *tmp;
DBUG_ENTER("unescape");
if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME))))
die(EX_MYSQLERR, "Couldn't allocate memory");

mysql_real_escape_string(&mysql_connection, tmp, pos, length);
mysql_real_escape_string(&mysql_connection, tmp, pos, (ulong)length);
fputc('\'', file);
fputs(tmp, file);
fputc('\'', file);
Expand Down Expand Up @@ -1724,7 +1724,7 @@ static char *quote_for_like(const char *name, char *buff)
Quote '<' '>' '&' '\"' chars and print a string to the xml_file.
*/

static void print_quoted_xml(FILE *xml_file, const char *str, ulong len,
static void print_quoted_xml(FILE *xml_file, const char *str, size_t len,
my_bool is_attribute_name)
{
const char *end;
Expand Down Expand Up @@ -1983,7 +1983,7 @@ static void print_xml_row(FILE *xml_file, const char *row_name,
squeezed to a single hyphen.
*/

static void print_xml_comment(FILE *xml_file, ulong len,
static void print_xml_comment(FILE *xml_file, size_t len,
const char *comment_string)
{
const char* end;
Expand Down Expand Up @@ -2100,7 +2100,7 @@ static uint dump_events_for_db(char *db)
DBUG_ENTER("dump_events_for_db");
DBUG_PRINT("enter", ("db: '%s'", db));

mysql_real_escape_string(mysql, db_name_buff, db, strlen(db));
mysql_real_escape_string(mysql, db_name_buff, db, (ulong)strlen(db));

/* nice comments */
print_comment(sql_file, 0,
Expand Down Expand Up @@ -2219,6 +2219,11 @@ static uint dump_events_for_db(char *db)
(const char *) (query_str != NULL ? query_str : row[3]),
(const char *) delimiter);

if(query_str)
{
my_free(query_str);
query_str= NULL;
}
restore_time_zone(sql_file, delimiter);
restore_sql_mode(sql_file, delimiter);

Expand Down Expand Up @@ -2312,7 +2317,7 @@ static uint dump_routines_for_db(char *db)
DBUG_ENTER("dump_routines_for_db");
DBUG_PRINT("enter", ("db: '%s'", db));

mysql_real_escape_string(mysql, db_name_buff, db, strlen(db));
mysql_real_escape_string(mysql, db_name_buff, db, (ulong)strlen(db));

/* nice comments */
print_comment(sql_file, 0,
Expand Down Expand Up @@ -2366,9 +2371,9 @@ static uint dump_routines_for_db(char *db)
if the user has EXECUTE privilege he see routine names, but NOT the
routine body of other routines that are not the creator of!
*/
DBUG_PRINT("info",("length of body for %s row[2] '%s' is %d",
DBUG_PRINT("info",("length of body for %s row[2] '%s' is %zu",
routine_name, row[2] ? row[2] : "(null)",
row[2] ? (int) strlen(row[2]) : 0));
row[2] ? strlen(row[2]) : 0));
if (row[2] == NULL)
{
print_comment(sql_file, 1, "\n-- insufficient privileges to %s\n",
Expand Down Expand Up @@ -3915,7 +3920,7 @@ static int dump_tablespaces_for_tables(char *db, char **table_names, int tables)
int i;
char name_buff[NAME_LEN*2+3];

mysql_real_escape_string(mysql, name_buff, db, strlen(db));
mysql_real_escape_string(mysql, name_buff, db, (ulong)strlen(db));

init_dynamic_string_checked(&where, " AND TABLESPACE_NAME IN ("
"SELECT DISTINCT TABLESPACE_NAME FROM"
Expand All @@ -3928,7 +3933,7 @@ static int dump_tablespaces_for_tables(char *db, char **table_names, int tables)
for (i=0 ; i<tables ; i++)
{
mysql_real_escape_string(mysql, name_buff,
table_names[i], strlen(table_names[i]));
table_names[i], (ulong)strlen(table_names[i]));

dynstr_append_checked(&where, "'");
dynstr_append_checked(&where, name_buff);
Expand Down Expand Up @@ -3959,7 +3964,7 @@ static int dump_tablespaces_for_databases(char** databases)
{
char db_name_buff[NAME_LEN*2+3];
mysql_real_escape_string(mysql, db_name_buff,
databases[i], strlen(databases[i]));
databases[i], (ulong)strlen(databases[i]));
dynstr_append_checked(&where, "'");
dynstr_append_checked(&where, db_name_buff);
dynstr_append_checked(&where, "',");
Expand Down Expand Up @@ -5086,7 +5091,7 @@ static int start_transaction(MYSQL *mysql_con)
}


static ulong find_set(TYPELIB *lib, const char *x, uint length,
static ulong find_set(TYPELIB *lib, const char *x, size_t length,
char **err_pos, uint *err_len)
{
const char *end= x + length;
Expand Down Expand Up @@ -5144,7 +5149,7 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
fputc(' ',file);
fputs(prefix, file);
if (string_value)
unescape(file,row[0],(uint) strlen(row[0]));
unescape(file,row[0], strlen(row[0]));
else
fputs(row[0], file);
check_io(file);
Expand Down Expand Up @@ -5554,8 +5559,8 @@ static my_bool get_view_structure(char *table, char* db)
verbose_msg("-- Retrieving view structure for table %s...\n", table);

#ifdef NOT_REALLY_USED_YET
sprintf(insert_pat,"SET SQL_QUOTE_SHOW_CREATE=%d",
(opt_quoted || opt_keywords));
dynstr_append_checked(&insert_pat, "SET SQL_QUOTE_SHOW_CREATE=");
dynstr_append_checked(&insert_pat, (opt_quoted || opt_keywords)? "1":"0");
#endif

result_table= quote_name(table, table_buff, 1);
Expand Down
Loading

0 comments on commit ab3d743

Please sign in to comment.