summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorKnut Anders Hatlen <knut.hatlen@oracle.com>2016-01-07 12:53:18 +0100
committerKnut Anders Hatlen <knut.hatlen@oracle.com>2016-01-17 20:28:00 +0100
commit95825fa28a7e84a2f5dbdef5241078f7055c5b04 (patch)
tree516eb39b4ff3d1a9830506025b2d83fc487680e2 /sql
parent79032a7ae1b4e000028a64ab0d2f216d4c23767b (diff)
downloadmariadb-git-95825fa28a7e84a2f5dbdef5241078f7055c5b04.tar.gz
Bug#21682356: STOP INJECTING DATA ITEMS IN AN ERROR MESSAGE
GENERATED BY THE EXP() FUNCTION When generating the error message for numeric overflow, pass a flag to Item::print() that prevents it from expanding constant expressions and parameters to the values they evaluate to. For consistency, also pass the flag to Item::print() when Item_func_spatial_collection::fix_length_and_dec() generates an error message. It doesn't make any difference at the moment, since constant expressions haven't been evaluated yet when this function is called.
Diffstat (limited to 'sql')
-rw-r--r--sql/item.cc7
-rw-r--r--sql/item_func.h4
-rw-r--r--sql/item_geofunc.h4
-rw-r--r--sql/mysqld.h10
-rw-r--r--sql/sql_select.cc40
5 files changed, 46 insertions, 19 deletions
diff --git a/sql/item.cc b/sql/item.cc
index beb68c5d321..5f02b96e59f 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -3456,7 +3456,7 @@ Item_param::eq(const Item *arg, bool binary_cmp) const
void Item_param::print(String *str, enum_query_type query_type)
{
- if (state == NO_VALUE)
+ if (state == NO_VALUE || query_type & QT_NO_DATA_EXPANSION)
{
str->append('?');
}
@@ -6197,7 +6197,8 @@ Item *Item_field::update_value_transformer(uchar *select_arg)
void Item_field::print(String *str, enum_query_type query_type)
{
- if (field && field->table->const_table)
+ if (field && field->table->const_table &&
+ !(query_type & QT_NO_DATA_EXPANSION))
{
char buff[MAX_FIELD_WIDTH];
String tmp(buff,sizeof(buff),str->charset());
diff --git a/sql/item_func.h b/sql/item_func.h
index fc9fa4a65fb..6c83bc179f2 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -1,7 +1,7 @@
#ifndef ITEM_FUNC_INCLUDED
#define ITEM_FUNC_INCLUDED
-/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -217,7 +217,7 @@ public:
char buf[256];
String str(buf, sizeof(buf), system_charset_info);
str.length(0);
- print(&str, QT_ORDINARY);
+ print(&str, QT_NO_DATA_EXPANSION);
my_error(ER_DATA_OUT_OF_RANGE, MYF(0), type_name, str.c_ptr_safe());
}
inline double raise_float_overflow()
diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h
index 903257525f9..fe7ccf10fcc 100644
--- a/sql/item_geofunc.h
+++ b/sql/item_geofunc.h
@@ -1,7 +1,7 @@
#ifndef ITEM_GEOFUNC_INCLUDED
#define ITEM_GEOFUNC_INCLUDED
-/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -187,7 +187,7 @@ public:
if (args[i]->fixed && args[i]->field_type() != MYSQL_TYPE_GEOMETRY)
{
String str;
- args[i]->print(&str, QT_ORDINARY);
+ args[i]->print(&str, QT_NO_DATA_EXPANSION);
str.append('\0');
my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "non geometric",
str.ptr());
diff --git a/sql/mysqld.h b/sql/mysqld.h
index 0253c2a0b43..ee9f8c64840 100644
--- a/sql/mysqld.h
+++ b/sql/mysqld.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -431,7 +431,13 @@ enum enum_query_type
/// In utf8.
QT_TO_SYSTEM_CHARSET= (1 << 0),
/// Without character set introducers.
- QT_WITHOUT_INTRODUCERS= (1 << 1)
+ QT_WITHOUT_INTRODUCERS= (1 << 1),
+ /**
+ If an expression is constant, print the expression, not the value
+ it evaluates to. Should be used for error messages, so that they
+ don't reveal values.
+ */
+ QT_NO_DATA_EXPANSION= (1 << 9),
};
/* query_id */
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 96271f26b0f..b5ecebdadc8 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1,4 +1,4 @@
-/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17427,26 +17427,46 @@ static void print_join(THD *thd,
/* List is reversed => we should reverse it before using */
List_iterator_fast<TABLE_LIST> ti(*tables);
TABLE_LIST **table;
- uint non_const_tables= 0;
+
+ /*
+ If the QT_NO_DATA_EXPANSION flag is specified, we print the
+ original table list, including constant tables that have been
+ optimized away, as the constant tables may be referenced in the
+ expression printed by Item_field::print() when this flag is given.
+ Otherwise, only non-const tables are printed.
+
+ Example:
+
+ Original SQL:
+ select * from (select 1) t
+
+ Printed without QT_NO_DATA_EXPANSION:
+ select '1' AS `1` from dual
+
+ Printed with QT_NO_DATA_EXPANSION:
+ select `t`.`1` from (select 1 AS `1`) `t`
+ */
+ const bool print_const_tables= (query_type & QT_NO_DATA_EXPANSION);
+ size_t tables_to_print= 0;
for (TABLE_LIST *t= ti++; t ; t= ti++)
- if (!t->optimized_away)
- non_const_tables++;
- if (!non_const_tables)
+ if (print_const_tables || !t->optimized_away)
+ tables_to_print++;
+ if (tables_to_print == 0)
{
str->append(STRING_WITH_LEN("dual"));
return; // all tables were optimized away
}
ti.rewind();
- if (!(table= (TABLE_LIST **)thd->alloc(sizeof(TABLE_LIST*) *
- non_const_tables)))
+ if (!(table= static_cast<TABLE_LIST **>(thd->alloc(sizeof(TABLE_LIST*) *
+ tables_to_print))))
return; // out of memory
- TABLE_LIST *tmp, **t= table + (non_const_tables - 1);
+ TABLE_LIST *tmp, **t= table + (tables_to_print - 1);
while ((tmp= ti++))
{
- if (tmp->optimized_away)
+ if (tmp->optimized_away && !print_const_tables)
continue;
*t--= tmp;
}
@@ -17454,7 +17474,7 @@ static void print_join(THD *thd,
DBUG_ASSERT(tables->elements >= 1);
(*table)->print(thd, str, query_type);
- TABLE_LIST **end= table + non_const_tables;
+ TABLE_LIST **end= table + tables_to_print;
for (TABLE_LIST **tbl= table + 1; tbl < end; tbl++)
{
TABLE_LIST *curr= *tbl;