summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorGeorgi Kodinov <Georgi.Kodinov@Oracle.com>2011-04-07 12:24:10 +0300
committerGeorgi Kodinov <Georgi.Kodinov@Oracle.com>2011-04-07 12:24:10 +0300
commit2db44e8bb438cc14161aeec24417ee8c04bd98e6 (patch)
treed3c262164be57c2fe1fb85782cac6633259bf3f3 /sql
parenta4d073ccc0bf154912ca4b22ee062d920bcd34c9 (diff)
parent5321b3a57a5191471cba0db85a11e21fb702200a (diff)
downloadmariadb-git-2db44e8bb438cc14161aeec24417ee8c04bd98e6.tar.gz
merged mysql-5.1->mysql-5.1-security
Diffstat (limited to 'sql')
-rw-r--r--sql/event_db_repository.cc2
-rw-r--r--sql/field.h2
-rw-r--r--sql/handler.h1
-rw-r--r--sql/item.cc8
-rw-r--r--sql/item_func.cc13
-rw-r--r--sql/item_timefunc.cc5
-rw-r--r--sql/item_timefunc.h7
-rw-r--r--sql/log_event.cc31
-rw-r--r--sql/mysqld.cc8
-rw-r--r--sql/set_var.cc38
-rw-r--r--sql/sql_base.cc3
-rw-r--r--sql/sql_show.cc12
12 files changed, 104 insertions, 26 deletions
diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc
index 753e9d21b65..7473cf47188 100644
--- a/sql/event_db_repository.cc
+++ b/sql/event_db_repository.cc
@@ -424,7 +424,7 @@ Event_db_repository::index_read_for_db_for_i_s(THD *thd, TABLE *schema_table,
key_copy(key_buf, event_table->record[0], key_info, key_len);
if (!(ret= event_table->file->index_read_map(event_table->record[0], key_buf,
(key_part_map)1,
- HA_READ_PREFIX)))
+ HA_READ_KEY_EXACT)))
{
DBUG_PRINT("info",("Found rows. Let's retrieve them. ret=%d", ret));
do
diff --git a/sql/field.h b/sql/field.h
index cbdfa686ff8..285c8307634 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -13,6 +13,8 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+#include "my_compare.h" /* for clr_rec_bits */
+
/*
Because of the function new_field() all field classes that have static
variables must declare the size_of() member function.
diff --git a/sql/handler.h b/sql/handler.h
index dabc179079a..5f68bb6a8f8 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -20,7 +20,6 @@
#pragma interface /* gcc class implementation */
#endif
-#include <my_handler.h>
#include <ft_global.h>
#include <keycache.h>
diff --git a/sql/item.cc b/sql/item.cc
index 357cc6d7fe4..24c3107ece9 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -926,8 +926,12 @@ bool Item::get_date(MYSQL_TIME *ltime,uint fuzzydate)
}
else
{
- longlong value= val_int();
int was_cut;
+ longlong value= val_int();
+
+ if (null_value)
+ goto err;
+
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == LL(-1))
{
char buff[22], *end;
@@ -7105,7 +7109,7 @@ String *Item_cache_int::val_str(String *str)
DBUG_ASSERT(fixed == 1);
if (!value_cached && !cache_value())
return NULL;
- str->set(value, default_charset());
+ str->set_int(value, unsigned_flag, default_charset());
return str;
}
diff --git a/sql/item_func.cc b/sql/item_func.cc
index efae928a8b6..595629b51be 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -482,7 +482,10 @@ bool Item_func::is_expensive_processor(uchar *arg)
my_decimal *Item_func::val_decimal(my_decimal *decimal_value)
{
DBUG_ASSERT(fixed);
- int2my_decimal(E_DEC_FATAL_ERROR, val_int(), unsigned_flag, decimal_value);
+ longlong nr= val_int();
+ if (null_value)
+ return 0; /* purecov: inspected */
+ int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
return decimal_value;
}
@@ -1803,9 +1806,10 @@ void Item_func_integer::fix_length_and_dec()
void Item_func_int_val::fix_num_length_and_dec()
{
- max_length= args[0]->max_length - (args[0]->decimals ?
- args[0]->decimals + 1 :
- 0) + 2;
+ ulonglong tmp_max_length= (ulonglong ) args[0]->max_length -
+ (args[0]->decimals ? args[0]->decimals + 1 : 0) + 2;
+ max_length= tmp_max_length > (ulonglong) max_field_size ?
+ max_field_size : (uint32) tmp_max_length;
uint tmp= float_length(decimals);
set_if_smaller(max_length,tmp);
decimals= 0;
@@ -3840,6 +3844,7 @@ Item_func_set_user_var::fix_length_and_dec()
maybe_null=args[0]->maybe_null;
max_length=args[0]->max_length;
decimals=args[0]->decimals;
+ unsigned_flag= args[0]->unsigned_flag;
collation.set(args[0]->collation.collation, DERIVATION_IMPLICIT);
}
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 74aae94b6f2..797b8cffb92 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -294,8 +294,8 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
for (; ptr != end && val != val_end; ptr++)
{
/* Skip pre-space between each argument */
- while (val != val_end && my_isspace(cs, *val))
- val++;
+ if ((val+= cs->cset->scan(cs, val, val_end, MY_SEQ_SPACES)) >= val_end)
+ break;
if (*ptr == '%' && ptr+1 != end)
{
@@ -3306,6 +3306,7 @@ void Item_func_str_to_date::fix_length_and_dec()
{
maybe_null= 1;
decimals=0;
+ cached_format_type= DATE_TIME;
cached_field_type= MYSQL_TYPE_DATETIME;
max_length= MAX_DATETIME_FULL_WIDTH*MY_CHARSET_BIN_MB_MAXLEN;
cached_timestamp_type= MYSQL_TIMESTAMP_NONE;
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 9c1ac512bcb..396b5bbb200 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -106,8 +106,11 @@ public:
{ DBUG_ASSERT(fixed == 1); return (double) Item_func_month::val_int(); }
String *val_str(String *str)
{
- str->set(val_int(), &my_charset_bin);
- return null_value ? 0 : str;
+ longlong nr= val_int();
+ if (null_value)
+ return 0;
+ str->set(nr, &my_charset_bin);
+ return str;
}
const char *func_name() const { return "month"; }
enum Item_result result_type () const { return INT_RESULT; }
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 0b938df1987..19f82b69048 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -8888,7 +8888,19 @@ static bool record_compare(TABLE *table)
}
}
- if (table->s->blob_fields + table->s->varchar_fields == 0)
+ /**
+ Compare full record only if:
+ - there are no blob fields (otherwise we would also need
+ to compare blobs contents as well);
+ - there are no varchar fields (otherwise we would also need
+ to compare varchar contents as well);
+ - there are no null fields, otherwise NULLed fields
+ contents (i.e., the don't care bytes) may show arbitrary
+ values, depending on how each engine handles internally.
+ */
+ if ((table->s->blob_fields +
+ table->s->varchar_fields +
+ table->s->null_fields) == 0)
{
result= cmp_record(table,record[1]);
goto record_compare_exit;
@@ -8903,13 +8915,22 @@ static bool record_compare(TABLE *table)
goto record_compare_exit;
}
- /* Compare updated fields */
+ /* Compare fields */
for (Field **ptr=table->field ; *ptr ; ptr++)
{
- if ((*ptr)->cmp_binary_offset(table->s->rec_buff_length))
+
+ /**
+ We only compare field contents that are not null.
+ NULL fields (i.e., their null bits) were compared
+ earlier.
+ */
+ if (!(*(ptr))->is_null())
{
- result= TRUE;
- goto record_compare_exit;
+ if ((*ptr)->cmp_binary_offset(table->s->rec_buff_length))
+ {
+ result= TRUE;
+ goto record_compare_exit;
+ }
}
}
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 46376a08ec9..54850f36d10 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -8795,6 +8795,14 @@ static int get_options(int *argc,char **argv)
opt_log_slow_slave_statements) &&
!opt_slow_log)
sql_print_warning("options --log-slow-admin-statements, --log-queries-not-using-indexes and --log-slow-slave-statements have no effect if --log_slow_queries is not set");
+ if (global_system_variables.net_buffer_length >
+ global_system_variables.max_allowed_packet)
+ {
+ sql_print_warning("net_buffer_length (%lu) is set to be larger "
+ "than max_allowed_packet (%lu). Please rectify.",
+ global_system_variables.net_buffer_length,
+ global_system_variables.max_allowed_packet);
+ }
#if defined(HAVE_BROKEN_REALPATH)
my_use_symdir=0;
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 333fb90c795..76957e32536 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -147,6 +147,8 @@ static void sys_default_general_log_path(THD *thd, enum_var_type type);
static bool sys_update_slow_log_path(THD *thd, set_var * var);
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
static uchar *get_myisam_mmap_size(THD *thd);
+static int check_max_allowed_packet(THD *thd, set_var *var);
+static int check_net_buffer_length(THD *thd, set_var *var);
/*
Variable definition list
@@ -360,7 +362,8 @@ static sys_var_const sys_lower_case_table_names(&vars,
(uchar*)
&lower_case_table_names);
static sys_var_thd_ulong_session_readonly sys_max_allowed_packet(&vars, "max_allowed_packet",
- &SV::max_allowed_packet);
+ &SV::max_allowed_packet,
+ check_max_allowed_packet);
static sys_var_ulonglong_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
&max_binlog_cache_size);
static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size",
@@ -450,7 +453,8 @@ static sys_var_const sys_named_pipe(&vars, "named_pipe",
/* purecov: end */
#endif
static sys_var_thd_ulong_session_readonly sys_net_buffer_length(&vars, "net_buffer_length",
- &SV::net_buffer_length);
+ &SV::net_buffer_length,
+ check_net_buffer_length);
static sys_var_thd_ulong sys_net_read_timeout(&vars, "net_read_timeout",
&SV::net_read_timeout,
0, fix_net_read_timeout);
@@ -4312,6 +4316,36 @@ uchar *sys_var_event_scheduler::value_ptr(THD *thd, enum_var_type type,
}
#endif
+
+int
+check_max_allowed_packet(THD *thd, set_var *var)
+{
+ longlong val= var->value->val_int();
+ if (val < (longlong) global_system_variables.net_buffer_length)
+ {
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_UNKNOWN_ERROR,
+ "The value of 'max_allowed_packet' should be no less than "
+ "the value of 'net_buffer_length'");
+ }
+ return 0;
+}
+
+
+int
+check_net_buffer_length(THD *thd, set_var *var)
+{
+ longlong val= var->value->val_int();
+ if (val > (longlong) global_system_variables.max_allowed_packet)
+ {
+ push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_UNKNOWN_ERROR,
+ "The value of 'max_allowed_packet' should be no less than "
+ "the value of 'net_buffer_length'");
+ }
+ return 0;
+}
+
/****************************************************************************
Used templates
****************************************************************************/
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 9765148cda1..dc78f3b84c6 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -2798,10 +2798,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
("Found table '%s.%s' with different refresh version",
table_list->db, table_list->table_name));
- /* Ignore FLUSH, but not name locks! */
+ /* Ignore FLUSH and pending name locks, but not acquired name locks! */
if (flags & MYSQL_LOCK_IGNORE_FLUSH && !table->open_placeholder)
{
- DBUG_ASSERT(table->db_stat);
/* Force close at once after usage */
thd->version= table->s->version;
continue;
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 1524a8fb87f..5b835096042 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -3399,6 +3399,12 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
it.rewind(); /* To get access to new elements in basis list */
while ((db_name= it++))
{
+ LEX_STRING orig_db_name;
+
+ /* db_name can be changed in make_table_list() func */
+ if (!thd->make_lex_string(&orig_db_name, db_name->str,
+ db_name->length, FALSE))
+ goto err;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (!(check_access(thd,SELECT_ACL, db_name->str,
&thd->col_access, 0, 1, with_i_schema) ||
@@ -3461,17 +3467,13 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
}
int res;
- LEX_STRING tmp_lex_string, orig_db_name;
+ LEX_STRING tmp_lex_string;
/*
Set the parent lex of 'sel' because it is needed by
sel.init_query() which is called inside make_table_list.
*/
thd->no_warnings_for_error= 1;
sel.parent_lex= lex;
- /* db_name can be changed in make_table_list() func */
- if (!thd->make_lex_string(&orig_db_name, db_name->str,
- db_name->length, FALSE))
- goto err;
if (make_table_list(thd, &sel, db_name, table_name))
goto err;
TABLE_LIST *show_table_list= sel.table_list.first;