1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Changing field::field_name and Item::name to LEX_CSTRING

Benefits of this patch:
- Removed a lot of calls to strlen(), especially for field_string
- Strings generated by parser are now const strings, less chance of
  accidently changing a string
- Removed a lot of calls with LEX_STRING as parameter (changed to pointer)
- More uniform code
- Item::name_length was not kept up to date. Now fixed
- Several bugs found and fixed (Access to null pointers,
  access of freed memory, wrong arguments to printf like functions)
- Removed a lot of casts from (const char*) to (char*)

Changes:
- This caused some ABI changes
  - lex_string_set now uses LEX_CSTRING
  - Some fucntions are now taking const char* instead of char*
- Create_field::change and after changed to LEX_CSTRING
- handler::connect_string, comment and engine_name() changed to LEX_CSTRING
- Checked printf() related calls to find bugs. Found and fixed several
  errors in old code.
- A lot of changes from LEX_STRING to LEX_CSTRING, especially related to
  parsing and events.
- Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING*
- Some changes for char* to const char*
- Added printf argument checking for my_snprintf()
- Introduced null_clex_str, star_clex_string, temp_lex_str to simplify
  code
- Added item_empty_name and item_used_name to be able to distingush between
  items that was given an empty name and items that was not given a name
  This is used in sql_yacc.yy to know when to give an item a name.
- select table_name."*' is not anymore same as table_name.*
- removed not used function Item::rename()
- Added comparision of item->name_length before some calls to
  my_strcasecmp() to speed up comparison
- Moved Item_sp_variable::make_field() from item.h to item.cc
- Some minimal code changes to avoid copying to const char *
- Fixed wrong error message in wsrep_mysql_parse()
- Fixed wrong code in find_field_in_natural_join() where real_item() was
  set when it shouldn't
- ER_ERROR_ON_RENAME was used with extra arguments.
- Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already
  give the error.

TODO:
- Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c
- Change code to not modify LEX_CSTRING for database name
  (as part of lower_case_table_names)
This commit is contained in:
Monty
2017-04-23 19:39:57 +03:00
parent cba84469eb
commit 5a759d31f7
233 changed files with 4155 additions and 3794 deletions

View File

@ -296,10 +296,10 @@ public:
sys_var_pluginvar *cast_pluginvar() { return this; }
uchar* real_value_ptr(THD *thd, enum_var_type type);
TYPELIB* plugin_var_typelib(void);
uchar* do_value_ptr(THD *thd, enum_var_type type, const LEX_STRING *base);
uchar* session_value_ptr(THD *thd, const LEX_STRING *base)
uchar* do_value_ptr(THD *thd, enum_var_type type, const LEX_CSTRING *base);
uchar* session_value_ptr(THD *thd, const LEX_CSTRING *base)
{ return do_value_ptr(thd, OPT_SESSION, base); }
uchar* global_value_ptr(THD *thd, const LEX_STRING *base)
uchar* global_value_ptr(THD *thd, const LEX_CSTRING *base)
{ return do_value_ptr(thd, OPT_GLOBAL, base); }
uchar *default_value_ptr(THD *thd)
{ return do_value_ptr(thd, OPT_DEFAULT, 0); }
@ -364,7 +364,7 @@ bool check_valid_path(const char *path, size_t len)
return prefix < len;
}
static void fix_dl_name(MEM_ROOT *root, LEX_STRING *dl)
static void fix_dl_name(MEM_ROOT *root, LEX_CSTRING *dl)
{
const size_t so_ext_len= sizeof(SO_EXT) - 1;
if (my_strcasecmp(&my_charset_latin1, dl->str + dl->length - so_ext_len,
@ -444,7 +444,7 @@ static int item_val_real(struct st_mysql_value *value, double *buf)
#ifdef HAVE_DLOPEN
static struct st_plugin_dl *plugin_dl_find(const LEX_STRING *dl)
static struct st_plugin_dl *plugin_dl_find(const LEX_CSTRING *dl)
{
uint i;
struct st_plugin_dl *tmp;
@ -500,7 +500,7 @@ static void free_plugin_mem(struct st_plugin_dl *p)
if (p->handle)
dlclose(p->handle);
#endif
my_free(p->dl.str);
my_free(const_cast<char*>(p->dl.str));
if (p->allocated)
my_free(p->plugins);
}
@ -720,7 +720,7 @@ static my_bool read_maria_plugin_info(struct st_plugin_dl *plugin_dl,
}
#endif /* HAVE_DLOPEN */
static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
static st_plugin_dl *plugin_dl_add(const LEX_CSTRING *dl, int report)
{
#ifdef HAVE_DLOPEN
char dlpath[FN_REFLEN];
@ -739,7 +739,7 @@ static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
plugin directory are used (to make this even remotely secure).
*/
if (check_valid_path(dl->str, dl->length) ||
check_string_char_length((LEX_STRING *) dl, 0, NAME_CHAR_LEN,
check_string_char_length((LEX_CSTRING *) dl, 0, NAME_CHAR_LEN,
system_charset_info, 1) ||
plugin_dir_len + dl->length + 1 >= FN_REFLEN)
{
@ -832,10 +832,12 @@ static st_plugin_dl *plugin_dl_add(const LEX_STRING *dl, int report)
static_cast<int>(plugin_dl.dl.length));
goto ret;
}
plugin_dl.dl.length= copy_and_convert(plugin_dl.dl.str, plugin_dl.dl.length,
files_charset_info, dl->str, dl->length, system_charset_info,
&dummy_errors);
plugin_dl.dl.str[plugin_dl.dl.length]= 0;
plugin_dl.dl.length= copy_and_convert((char*) plugin_dl.dl.str,
plugin_dl.dl.length,
files_charset_info, dl->str,
dl->length, system_charset_info,
&dummy_errors);
((char*) plugin_dl.dl.str)[plugin_dl.dl.length]= 0;
/* Add this dll to array */
if (! (tmp= plugin_dl_insert_or_reuse(&plugin_dl)))
{
@ -878,7 +880,8 @@ static void plugin_dl_del(struct st_plugin_dl *plugin_dl)
}
static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int type)
static struct st_plugin_int *plugin_find_internal(const LEX_CSTRING *name,
int type)
{
uint i;
DBUG_ENTER("plugin_find_internal");
@ -905,7 +908,7 @@ static struct st_plugin_int *plugin_find_internal(const LEX_STRING *name, int ty
}
static SHOW_COMP_OPTION plugin_status(const LEX_STRING *name, int type)
static SHOW_COMP_OPTION plugin_status(const LEX_CSTRING *name, int type)
{
SHOW_COMP_OPTION rc= SHOW_OPTION_NO;
struct st_plugin_int *plugin;
@ -922,7 +925,7 @@ static SHOW_COMP_OPTION plugin_status(const LEX_STRING *name, int type)
}
bool plugin_is_ready(const LEX_STRING *name, int type)
bool plugin_is_ready(const LEX_CSTRING *name, int type)
{
bool rc= FALSE;
if (plugin_status(name, type) == SHOW_OPTION_YES)
@ -933,7 +936,7 @@ bool plugin_is_ready(const LEX_STRING *name, int type)
SHOW_COMP_OPTION plugin_status(const char *name, size_t len, int type)
{
LEX_STRING plugin_name= { (char *) name, len };
LEX_CSTRING plugin_name= { name, len };
return plugin_status(&plugin_name, type);
}
@ -1017,7 +1020,7 @@ plugin_ref plugin_lock(THD *thd, plugin_ref ptr)
}
plugin_ref plugin_lock_by_name(THD *thd, const LEX_STRING *name, int type)
plugin_ref plugin_lock_by_name(THD *thd, const LEX_CSTRING *name, int type)
{
LEX *lex= thd ? thd->lex : 0;
plugin_ref rc= NULL;
@ -1060,7 +1063,7 @@ static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
Requires that a write-lock is held on LOCK_system_variables_hash
*/
static bool plugin_add(MEM_ROOT *tmp_root,
const LEX_STRING *name, LEX_STRING *dl, int report)
const LEX_CSTRING *name, LEX_CSTRING *dl, int report)
{
struct st_plugin_int tmp, *maybe_dupe;
struct st_maria_plugin *plugin;
@ -1527,7 +1530,7 @@ int plugin_init(int *argc, char **argv, int flags)
MEM_ROOT tmp_root;
bool reaped_mandatory_plugin= false;
bool mandatory= true;
LEX_STRING MyISAM= { C_STRING_WITH_LEN("MyISAM") };
LEX_CSTRING MyISAM= { STRING_WITH_LEN("MyISAM") };
DBUG_ENTER("plugin_init");
if (initialized)
@ -1650,7 +1653,7 @@ int plugin_init(int *argc, char **argv, int flags)
char path[FN_REFLEN + 1];
build_table_filename(path, sizeof(path) - 1, "mysql", "plugin", reg_ext, 0);
char engine_name_buf[NAME_CHAR_LEN + 1];
LEX_STRING maybe_myisam= { engine_name_buf, 0 };
LEX_CSTRING maybe_myisam= { engine_name_buf, 0 };
bool is_sequence;
Table_type frm_type= dd_frm_type(NULL, path, &maybe_myisam, &is_sequence);
/* if mysql.plugin table is MyISAM - load it right away */
@ -1809,8 +1812,8 @@ static void plugin_load(MEM_ROOT *tmp_root)
get_field(tmp_root, table->field[0], &str_name);
get_field(tmp_root, table->field[1], &str_dl);
LEX_STRING name= {(char *)str_name.ptr(), str_name.length()};
LEX_STRING dl= {(char *)str_dl.ptr(), str_dl.length()};
LEX_CSTRING name= {str_name.ptr(), str_name.length()};
LEX_CSTRING dl= {str_dl.ptr(), str_dl.length()};
/*
there're no other threads running yet, so we don't need a mutex.
@ -1873,14 +1876,16 @@ static bool plugin_load_list(MEM_ROOT *tmp_root, const char *list)
mysql_mutex_lock(&LOCK_plugin);
free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
name.str= 0; // load everything
if (plugin_add(tmp_root, &name, &dl, REPORT_TO_LOG))
if (plugin_add(tmp_root, (LEX_CSTRING*) &name, (LEX_CSTRING*) &dl,
REPORT_TO_LOG))
goto error;
}
else
{
free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
mysql_mutex_lock(&LOCK_plugin);
if (plugin_add(tmp_root, &name, &dl, REPORT_TO_LOG))
if (plugin_add(tmp_root, (LEX_CSTRING*) &name, (LEX_CSTRING*) &dl,
REPORT_TO_LOG))
goto error;
}
mysql_mutex_unlock(&LOCK_plugin);
@ -2048,7 +2053,7 @@ void plugin_shutdown(void)
That is, initialize it, and update mysql.plugin table
*/
static bool finalize_install(THD *thd, TABLE *table, const LEX_STRING *name,
static bool finalize_install(THD *thd, TABLE *table, const LEX_CSTRING *name,
int *argc, char **argv)
{
struct st_plugin_int *tmp= plugin_find_internal(name, MYSQL_ANY_PLUGIN);
@ -2102,12 +2107,12 @@ static bool finalize_install(THD *thd, TABLE *table, const LEX_STRING *name,
return 0;
}
bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
const LEX_STRING *dl_arg)
bool mysql_install_plugin(THD *thd, const LEX_CSTRING *name,
const LEX_CSTRING *dl_arg)
{
TABLE_LIST tables;
TABLE *table;
LEX_STRING dl= *dl_arg;
LEX_CSTRING dl= *dl_arg;
bool error;
int argc=orig_argc;
char **argv=orig_argv;
@ -2167,7 +2172,7 @@ bool mysql_install_plugin(THD *thd, const LEX_STRING *name,
struct st_maria_plugin *plugin;
for (plugin= plugin_dl->plugins; plugin->info; plugin++)
{
LEX_STRING str= { const_cast<char*>(plugin->name), strlen(plugin->name) };
LEX_CSTRING str= { plugin->name, strlen(plugin->name) };
error|= finalize_install(thd, table, &str, &argc, argv);
}
}
@ -2185,7 +2190,7 @@ err:
}
static bool do_uninstall(THD *thd, TABLE *table, const LEX_STRING *name)
static bool do_uninstall(THD *thd, TABLE *table, const LEX_CSTRING *name)
{
struct st_plugin_int *plugin;
mysql_mutex_assert_owner(&LOCK_plugin);
@ -2241,12 +2246,12 @@ static bool do_uninstall(THD *thd, TABLE *table, const LEX_STRING *name)
}
bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name,
const LEX_STRING *dl_arg)
bool mysql_uninstall_plugin(THD *thd, const LEX_CSTRING *name,
const LEX_CSTRING *dl_arg)
{
TABLE *table;
TABLE_LIST tables;
LEX_STRING dl= *dl_arg;
LEX_CSTRING dl= *dl_arg;
bool error= false;
DBUG_ENTER("mysql_uninstall_plugin");
@ -2298,7 +2303,7 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name,
for (struct st_maria_plugin *plugin= plugin_dl->plugins;
plugin->info; plugin++)
{
LEX_STRING str= { const_cast<char*>(plugin->name), strlen(plugin->name) };
LEX_CSTRING str= { plugin->name, strlen(plugin->name) };
error|= do_uninstall(thd, table, &str);
}
}
@ -2414,7 +2419,7 @@ static bool plugin_dl_foreach_internal(THD *thd, st_plugin_dl *plugin_dl,
return 0;
}
bool plugin_dl_foreach(THD *thd, const LEX_STRING *dl,
bool plugin_dl_foreach(THD *thd, const LEX_CSTRING *dl,
plugin_foreach_func *func, void *arg)
{
bool err= 0;
@ -3383,7 +3388,7 @@ TYPELIB* sys_var_pluginvar::plugin_var_typelib(void)
uchar* sys_var_pluginvar::do_value_ptr(THD *thd, enum_var_type type,
const LEX_STRING *base)
const LEX_CSTRING *base)
{
uchar* result;