Commit 87321362 authored by unknown's avatar unknown

Portability fixes

Fixes while reviewing new pushed code
NULL as argument to encrypt/decrypt should return NULL without a warning


client/mysqldump.c:
  Cleanup
  Ensure we free allocated memory
  Portability fixes
client/mysqltest.c:
  Cleanup of code during review
  Portability fixes (Don't use 'bool')
mysql-test/r/func_encrypt.result:
  NULL as argument to encrypt/decrypt should return NULL without a warning
mysql-test/r/func_encrypt_nossl.result:
  Added test of NULL argument
mysql-test/t/func_encrypt_nossl.test:
  Added test of NULL argument
sql/handler.cc:
  Cleanup during code review
sql/item_strfunc.cc:
  NULL as argument to encrypt/decrypt should return NULL without a warning
sql/sql_parse.cc:
  Fix wrong merge (fix was not needed as the previous code was reverted)
sql/sql_table.cc:
  Removed extra new line
parent 9712bb4c
...@@ -533,6 +533,12 @@ static void write_footer(FILE *sql_file) ...@@ -533,6 +533,12 @@ static void write_footer(FILE *sql_file)
} }
} /* write_footer */ } /* write_footer */
static void free_table_ent(char *key)
{
my_free((gptr) key, MYF(0));
}
byte* get_table_key(const char *entry, uint *length, byte* get_table_key(const char *entry, uint *length,
my_bool not_used __attribute__((unused))) my_bool not_used __attribute__((unused)))
...@@ -544,8 +550,9 @@ byte* get_table_key(const char *entry, uint *length, ...@@ -544,8 +550,9 @@ byte* get_table_key(const char *entry, uint *length,
void init_table_rule_hash(HASH* h) void init_table_rule_hash(HASH* h)
{ {
if(hash_init(h, charset_info, 16, 0, 0, if (hash_init(h, charset_info, 16, 0, 0,
(hash_get_key) get_table_key, 0, 0)) (hash_get_key) get_table_key,
(hash_free_key) free_table_ent, 0))
exit(EX_EOM); exit(EX_EOM);
} }
...@@ -933,13 +940,14 @@ static char *quote_name(const char *name, char *buff, my_bool force) ...@@ -933,13 +940,14 @@ static char *quote_name(const char *name, char *buff, my_bool force)
return buff; return buff;
} /* quote_name */ } /* quote_name */
/* /*
Quote a table name so it can be used in "SHOW TABLES LIKE <tabname>" Quote a table name so it can be used in "SHOW TABLES LIKE <tabname>"
SYNOPSIS SYNOPSIS
quote_for_like quote_for_like()
name - name of the table name name of the table
buff - quoted name of the table buff quoted name of the table
DESCRIPTION DESCRIPTION
Quote \, _, ' and % characters Quote \, _, ' and % characters
...@@ -955,7 +963,6 @@ static char *quote_name(const char *name, char *buff, my_bool force) ...@@ -955,7 +963,6 @@ static char *quote_name(const char *name, char *buff, my_bool force)
Example: "t\1" => "t\\\\1" Example: "t\1" => "t\\\\1"
*/ */
static char *quote_for_like(const char *name, char *buff) static char *quote_for_like(const char *name, char *buff)
{ {
char *to= buff; char *to= buff;
...@@ -2228,17 +2235,17 @@ static int get_actual_table_name(const char *old_table_name, ...@@ -2228,17 +2235,17 @@ static int get_actual_table_name(const char *old_table_name,
retval = 1; retval = 1;
if (tableRes != NULL) if (tableRes != NULL)
{ {
my_ulonglong numRows = mysql_num_rows(tableRes); my_ulonglong numRows= mysql_num_rows(tableRes);
if (numRows > 0) if (numRows > 0)
{ {
row= mysql_fetch_row( tableRes ); row= mysql_fetch_row( tableRes );
strmake(new_table_name, row[0], buf_size-1); strmake(new_table_name, row[0], buf_size-1);
retval = 0; retval= 0;
DBUG_PRINT("info", ("new_table_name: %s", new_table_name)); DBUG_PRINT("info", ("new_table_name: %s", new_table_name));
} }
mysql_free_result(tableRes); mysql_free_result(tableRes);
} }
DBUG_PRINT("exit", ("retval: %d", retval)); DBUG_PRINT("exit", ("retval: %d", retval));
DBUG_RETURN(retval); DBUG_RETURN(retval);
} }
...@@ -2250,7 +2257,6 @@ static int dump_selected_tables(char *db, char **table_names, int tables) ...@@ -2250,7 +2257,6 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
char new_table_name[NAME_LEN]; char new_table_name[NAME_LEN];
DYNAMIC_STRING lock_tables_query; DYNAMIC_STRING lock_tables_query;
HASH dump_tables; HASH dump_tables;
DBUG_ENTER("dump_selected_tables"); DBUG_ENTER("dump_selected_tables");
if (init_dumping(db)) if (init_dumping(db))
...@@ -2258,7 +2264,8 @@ static int dump_selected_tables(char *db, char **table_names, int tables) ...@@ -2258,7 +2264,8 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
/* Init hash table for storing the actual name of tables to dump */ /* Init hash table for storing the actual name of tables to dump */
if (hash_init(&dump_tables, charset_info, 16, 0, 0, if (hash_init(&dump_tables, charset_info, 16, 0, 0,
(hash_get_key) get_table_key, 0, 0)) (hash_get_key) get_table_key, (hash_free_key) free_table_ent,
0))
exit(EX_EOM); exit(EX_EOM);
init_dynamic_string(&lock_tables_query, "LOCK TABLES ", 256, 1024); init_dynamic_string(&lock_tables_query, "LOCK TABLES ", 256, 1024);
...@@ -2266,8 +2273,8 @@ static int dump_selected_tables(char *db, char **table_names, int tables) ...@@ -2266,8 +2273,8 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
{ {
/* the table name passed on commandline may be wrong case */ /* the table name passed on commandline may be wrong case */
if (!get_actual_table_name( *table_names, if (!get_actual_table_name(*table_names,
new_table_name, sizeof(new_table_name) )) new_table_name, sizeof(new_table_name) ))
{ {
/* Add found table name to lock_tables_query */ /* Add found table name to lock_tables_query */
if (lock_tables) if (lock_tables)
...@@ -2310,12 +2317,11 @@ static int dump_selected_tables(char *db, char **table_names, int tables) ...@@ -2310,12 +2317,11 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
print_xml_tag1(md_result_file, "", "database name=", db, "\n"); print_xml_tag1(md_result_file, "", "database name=", db, "\n");
/* Dump each selected table */ /* Dump each selected table */
const char *table_name;
for (i= 0 ; i < dump_tables.records ; i++) for (i= 0 ; i < dump_tables.records ; i++)
{ {
table_name= hash_element(&dump_tables, i); const char *table_name= hash_element(&dump_tables, i);
DBUG_PRINT("info",("Dumping table %s", table_name)); DBUG_PRINT("info",("Dumping table %s", table_name));
numrows = getTableStructure(table_name, db); numrows= getTableStructure(table_name, db);
if (!dFlag && numrows > 0) if (!dFlag && numrows > 0)
dumpTable(numrows, table_name); dumpTable(numrows, table_name);
} }
...@@ -2620,6 +2626,7 @@ int main(int argc, char **argv) ...@@ -2620,6 +2626,7 @@ int main(int argc, char **argv)
{ {
compatible_mode_normal_str[0]= 0; compatible_mode_normal_str[0]= 0;
default_charset= (char *)mysql_universal_client_charset; default_charset= (char *)mysql_universal_client_charset;
bzero((char*) &ignore_table, sizeof(ignore_table));
MY_INIT("mysqldump"); MY_INIT("mysqldump");
if (get_options(&argc, &argv)) if (get_options(&argc, &argv))
...@@ -2678,6 +2685,8 @@ int main(int argc, char **argv) ...@@ -2678,6 +2685,8 @@ int main(int argc, char **argv)
if (md_result_file != stdout) if (md_result_file != stdout)
my_fclose(md_result_file, MYF(0)); my_fclose(md_result_file, MYF(0));
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR)); my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
if (hash_inited(&ignore_table))
hash_free(&ignore_table);
if (extended_insert) if (extended_insert)
dynstr_free(&extended_row); dynstr_free(&extended_row);
if (insert_pat_inited) if (insert_pat_inited)
......
...@@ -964,28 +964,27 @@ static void do_exec(struct st_query* q) ...@@ -964,28 +964,27 @@ static void do_exec(struct st_query* q)
error= pclose(res_file); error= pclose(res_file);
if (error != 0) if (error != 0)
{ {
uint status= WEXITSTATUS(error); uint status= WEXITSTATUS(error), i;
if(q->abort_on_error) my_bool ok= 0;
if (q->abort_on_error)
die("At line %u: command \"%s\" failed", start_lineno, cmd); die("At line %u: command \"%s\" failed", start_lineno, cmd);
else
DBUG_PRINT("info",
("error: %d, status: %d", error, status));
for (i=0 ; (uint) i < q->expected_errors ; i++)
{ {
DBUG_PRINT("info", DBUG_PRINT("info", ("expected error: %d",
("error: %d, status: %d", error, status)); q->expected_errno[i].code.errnum));
bool ok= 0; if ((q->expected_errno[i].type == ERR_ERRNO) &&
uint i; (q->expected_errno[i].code.errnum == status))
for (i=0 ; (uint) i < q->expected_errors ; i++) ok= 1;
{ verbose_msg("At line %u: command \"%s\" failed with expected error: %d",
DBUG_PRINT("info", ("expected error: %d", q->expected_errno[i].code.errnum)); start_lineno, cmd, status);
if ((q->expected_errno[i].type == ERR_ERRNO) &&
(q->expected_errno[i].code.errnum == status))
ok= 1;
verbose_msg("At line %u: command \"%s\" failed with expected error: %d",
start_lineno, cmd, status);
}
if (!ok)
die("At line: %u: command \"%s\" failed with wrong error: %d",
start_lineno, cmd, status);
} }
if (!ok)
die("At line: %u: command \"%s\" failed with wrong error: %d",
start_lineno, cmd, status);
} }
else if (q->expected_errno[0].type == ERR_ERRNO && else if (q->expected_errno[0].type == ERR_ERRNO &&
q->expected_errno[0].code.errnum != 0) q->expected_errno[0].code.errnum != 0)
......
...@@ -128,18 +128,12 @@ Error 1108 Incorrect parameters to procedure 'des_encrypt' ...@@ -128,18 +128,12 @@ Error 1108 Incorrect parameters to procedure 'des_encrypt'
select des_encrypt(NULL); select des_encrypt(NULL);
des_encrypt(NULL) des_encrypt(NULL)
NULL NULL
Warnings:
Error 1108 Incorrect parameters to procedure 'des_encrypt'
select des_encrypt(NULL, 10); select des_encrypt(NULL, 10);
des_encrypt(NULL, 10) des_encrypt(NULL, 10)
NULL NULL
Warnings:
Error 1108 Incorrect parameters to procedure 'des_encrypt'
select des_encrypt(NULL, NULL); select des_encrypt(NULL, NULL);
des_encrypt(NULL, NULL) des_encrypt(NULL, NULL)
NULL NULL
Warnings:
Error 1108 Incorrect parameters to procedure 'des_encrypt'
select des_encrypt(10, NULL); select des_encrypt(10, NULL);
des_encrypt(10, NULL) des_encrypt(10, NULL)
NULL NULL
...@@ -156,18 +150,12 @@ hello ...@@ -156,18 +150,12 @@ hello
select des_decrypt(NULL); select des_decrypt(NULL);
des_decrypt(NULL) des_decrypt(NULL)
NULL NULL
Warnings:
Error 1108 Incorrect parameters to procedure 'des_decrypt'
select des_decrypt(NULL, 10); select des_decrypt(NULL, 10);
des_decrypt(NULL, 10) des_decrypt(NULL, 10)
NULL NULL
Warnings:
Error 1108 Incorrect parameters to procedure 'des_decrypt'
select des_decrypt(NULL, NULL); select des_decrypt(NULL, NULL);
des_decrypt(NULL, NULL) des_decrypt(NULL, NULL)
NULL NULL
Warnings:
Error 1108 Incorrect parameters to procedure 'des_decrypt'
select des_decrypt(10, NULL); select des_decrypt(10, NULL);
des_decrypt(10, NULL) des_decrypt(10, NULL)
10 10
......
...@@ -23,6 +23,10 @@ des_encrypt("test", NULL) ...@@ -23,6 +23,10 @@ des_encrypt("test", NULL)
NULL NULL
Warnings: Warnings:
Error 1289 The 'des_encrypt' feature is disabled; you need MySQL built with '--with-openssl' to have it working Error 1289 The 'des_encrypt' feature is disabled; you need MySQL built with '--with-openssl' to have it working
des_encrypt(NULL, NULL)
NULL
Warnings:
Error 1289 The 'des_encrypt' feature is disabled; you need MySQL built with '--with-openssl' to have it working
select des_decrypt("test", 'anotherkeystr'); select des_decrypt("test", 'anotherkeystr');
des_decrypt("test", 'anotherkeystr') des_decrypt("test", 'anotherkeystr')
NULL NULL
......
...@@ -9,6 +9,7 @@ select des_encrypt("test", 1); ...@@ -9,6 +9,7 @@ select des_encrypt("test", 1);
select des_encrypt("test", 9); select des_encrypt("test", 9);
select des_encrypt("test", 100); select des_encrypt("test", 100);
select des_encrypt("test", NULL); select des_encrypt("test", NULL);
select des_encrypt(NULL, NULL);
select des_decrypt("test", 'anotherkeystr'); select des_decrypt("test", 'anotherkeystr');
select des_decrypt(1, 1); select des_decrypt(1, 1);
select des_decrypt(des_encrypt("test", 'thekey')); select des_decrypt(des_encrypt("test", 'thekey'));
......
...@@ -1357,14 +1357,12 @@ int ha_create_table_from_engine(THD* thd, ...@@ -1357,14 +1357,12 @@ int ha_create_table_from_engine(THD* thd,
HA_CREATE_INFO create_info; HA_CREATE_INFO create_info;
TABLE table; TABLE table;
DBUG_ENTER("ha_create_table_from_engine"); DBUG_ENTER("ha_create_table_from_engine");
DBUG_PRINT("enter", ("name '%s'.'%s'", DBUG_PRINT("enter", ("name '%s'.'%s'", db, name));
db, name));
bzero((char*) &create_info,sizeof(create_info)); bzero((char*) &create_info,sizeof(create_info));
if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
if(error= ha_discover(thd, db, name, &frmblob, &frmlen))
{ {
// Table could not be discovered and thus not created /* Table could not be discovered and thus not created */
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -1375,11 +1373,10 @@ int ha_create_table_from_engine(THD* thd, ...@@ -1375,11 +1373,10 @@ int ha_create_table_from_engine(THD* thd,
(void)strxnmov(path,FN_REFLEN,mysql_data_home,"/",db,"/",name,NullS); (void)strxnmov(path,FN_REFLEN,mysql_data_home,"/",db,"/",name,NullS);
// Save the frm file // Save the frm file
if (writefrm(path, frmblob, frmlen)) error= writefrm(path, frmblob, frmlen);
{ my_free((char*) frmblob, MYF(0));
my_free((char*) frmblob, MYF(MY_ALLOW_ZERO_PTR)); if (error)
DBUG_RETURN(2); DBUG_RETURN(2);
}
if (openfrm(path,"",0,(uint) READ_ALL, 0, &table)) if (openfrm(path,"",0,(uint) READ_ALL, 0, &table))
DBUG_RETURN(3); DBUG_RETURN(3);
...@@ -1395,7 +1392,6 @@ int ha_create_table_from_engine(THD* thd, ...@@ -1395,7 +1392,6 @@ int ha_create_table_from_engine(THD* thd,
} }
error=table.file->create(path,&table,&create_info); error=table.file->create(path,&table,&create_info);
VOID(closefrm(&table)); VOID(closefrm(&table));
my_free((char*) frmblob, MYF(MY_ALLOW_ZERO_PTR));
DBUG_RETURN(error != 0); DBUG_RETURN(error != 0);
} }
......
...@@ -381,8 +381,8 @@ String *Item_func_des_encrypt::val_str(String *str) ...@@ -381,8 +381,8 @@ String *Item_func_des_encrypt::val_str(String *str)
uint key_number, res_length, tail; uint key_number, res_length, tail;
String *res= args[0]->val_str(str); String *res= args[0]->val_str(str);
if ((null_value=args[0]->null_value)) if ((null_value= args[0]->null_value))
goto error; return 0; // ENCRYPT(NULL) == NULL
if ((res_length=res->length()) == 0) if ((res_length=res->length()) == 0)
return &my_empty_string; return &my_empty_string;
...@@ -474,7 +474,7 @@ String *Item_func_des_decrypt::val_str(String *str) ...@@ -474,7 +474,7 @@ String *Item_func_des_decrypt::val_str(String *str)
uint length=res->length(),tail; uint length=res->length(),tail;
if ((null_value=args[0]->null_value)) if ((null_value=args[0]->null_value))
goto error; return 0;
length=res->length(); length=res->length();
if (length < 9 || (length % 8) != 1 || !((*res)[0] & 128)) if (length < 9 || (length % 8) != 1 || !((*res)[0] & 128))
return res; // Skip decryption if not encrypted return res; // Skip decryption if not encrypted
......
...@@ -2897,6 +2897,7 @@ mysql_execute_command(THD *thd) ...@@ -2897,6 +2897,7 @@ mysql_execute_command(THD *thd)
} }
else else
res= -1; res= -1;
first_local_table->next= tables;
lex->select_lex.table_list.first= (byte*) first_local_table; lex->select_lex.table_list.first= (byte*) first_local_table;
break; break;
} }
......
...@@ -255,7 +255,6 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -255,7 +255,6 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
table->real_name); table->real_name);
else else
error= 1; error= 1;
} }
else else
{ {
......
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