Skip to content

Commit 95825fa

Browse files
committed
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.
1 parent 79032a7 commit 95825fa

File tree

6 files changed

+48
-21
lines changed

6 files changed

+48
-21
lines changed

mysql-test/r/func_math.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,9 +632,9 @@ ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 DIV
632632
CREATE TABLE t1(a BIGINT, b BIGINT UNSIGNED);
633633
INSERT INTO t1 VALUES(-9223372036854775808, 9223372036854775809);
634634
SELECT -a FROM t1;
635-
ERROR 22003: BIGINT value is out of range in '-('-9223372036854775808')'
635+
ERROR 22003: BIGINT value is out of range in '-(`test`.`t1`.`a`)'
636636
SELECT -b FROM t1;
637-
ERROR 22003: BIGINT value is out of range in '-('9223372036854775809')'
637+
ERROR 22003: BIGINT value is out of range in '-(`test`.`t1`.`b`)'
638638
DROP TABLE t1;
639639
SET @a:=999999999999999999999999999999999999999999999999999999999999999999999999999999999;
640640
SELECT @a + @a;

sql/item.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
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
34563456

34573457
void Item_param::print(String *str, enum_query_type query_type)
34583458
{
3459-
if (state == NO_VALUE)
3459+
if (state == NO_VALUE || query_type & QT_NO_DATA_EXPANSION)
34603460
{
34613461
str->append('?');
34623462
}
@@ -6197,7 +6197,8 @@ Item *Item_field::update_value_transformer(uchar *select_arg)
61976197

61986198
void Item_field::print(String *str, enum_query_type query_type)
61996199
{
6200-
if (field && field->table->const_table)
6200+
if (field && field->table->const_table &&
6201+
!(query_type & QT_NO_DATA_EXPANSION))
62016202
{
62026203
char buff[MAX_FIELD_WIDTH];
62036204
String tmp(buff,sizeof(buff),str->charset());

sql/item_func.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ITEM_FUNC_INCLUDED
22
#define ITEM_FUNC_INCLUDED
33

4-
/* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -217,7 +217,7 @@ class Item_func :public Item_result_field
217217
char buf[256];
218218
String str(buf, sizeof(buf), system_charset_info);
219219
str.length(0);
220-
print(&str, QT_ORDINARY);
220+
print(&str, QT_NO_DATA_EXPANSION);
221221
my_error(ER_DATA_OUT_OF_RANGE, MYF(0), type_name, str.c_ptr_safe());
222222
}
223223
inline double raise_float_overflow()

sql/item_geofunc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ITEM_GEOFUNC_INCLUDED
22
#define ITEM_GEOFUNC_INCLUDED
33

4-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -187,7 +187,7 @@ class Item_func_spatial_collection: public Item_geometry_func
187187
if (args[i]->fixed && args[i]->field_type() != MYSQL_TYPE_GEOMETRY)
188188
{
189189
String str;
190-
args[i]->print(&str, QT_ORDINARY);
190+
args[i]->print(&str, QT_NO_DATA_EXPANSION);
191191
str.append('\0');
192192
my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "non geometric",
193193
str.ptr());

sql/mysqld.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -431,7 +431,13 @@ enum enum_query_type
431431
/// In utf8.
432432
QT_TO_SYSTEM_CHARSET= (1 << 0),
433433
/// Without character set introducers.
434-
QT_WITHOUT_INTRODUCERS= (1 << 1)
434+
QT_WITHOUT_INTRODUCERS= (1 << 1),
435+
/**
436+
If an expression is constant, print the expression, not the value
437+
it evaluates to. Should be used for error messages, so that they
438+
don't reveal values.
439+
*/
440+
QT_NO_DATA_EXPANSION= (1 << 9),
435441
};
436442

437443
/* query_id */

sql/sql_select.cc

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
22

33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -17427,34 +17427,54 @@ static void print_join(THD *thd,
1742717427
/* List is reversed => we should reverse it before using */
1742817428
List_iterator_fast<TABLE_LIST> ti(*tables);
1742917429
TABLE_LIST **table;
17430-
uint non_const_tables= 0;
17430+
17431+
/*
17432+
If the QT_NO_DATA_EXPANSION flag is specified, we print the
17433+
original table list, including constant tables that have been
17434+
optimized away, as the constant tables may be referenced in the
17435+
expression printed by Item_field::print() when this flag is given.
17436+
Otherwise, only non-const tables are printed.
17437+
17438+
Example:
17439+
17440+
Original SQL:
17441+
select * from (select 1) t
17442+
17443+
Printed without QT_NO_DATA_EXPANSION:
17444+
select '1' AS `1` from dual
17445+
17446+
Printed with QT_NO_DATA_EXPANSION:
17447+
select `t`.`1` from (select 1 AS `1`) `t`
17448+
*/
17449+
const bool print_const_tables= (query_type & QT_NO_DATA_EXPANSION);
17450+
size_t tables_to_print= 0;
1743117451

1743217452
for (TABLE_LIST *t= ti++; t ; t= ti++)
17433-
if (!t->optimized_away)
17434-
non_const_tables++;
17435-
if (!non_const_tables)
17453+
if (print_const_tables || !t->optimized_away)
17454+
tables_to_print++;
17455+
if (tables_to_print == 0)
1743617456
{
1743717457
str->append(STRING_WITH_LEN("dual"));
1743817458
return; // all tables were optimized away
1743917459
}
1744017460
ti.rewind();
1744117461

17442-
if (!(table= (TABLE_LIST **)thd->alloc(sizeof(TABLE_LIST*) *
17443-
non_const_tables)))
17462+
if (!(table= static_cast<TABLE_LIST **>(thd->alloc(sizeof(TABLE_LIST*) *
17463+
tables_to_print))))
1744417464
return; // out of memory
1744517465

17446-
TABLE_LIST *tmp, **t= table + (non_const_tables - 1);
17466+
TABLE_LIST *tmp, **t= table + (tables_to_print - 1);
1744717467
while ((tmp= ti++))
1744817468
{
17449-
if (tmp->optimized_away)
17469+
if (tmp->optimized_away && !print_const_tables)
1745017470
continue;
1745117471
*t--= tmp;
1745217472
}
1745317473

1745417474
DBUG_ASSERT(tables->elements >= 1);
1745517475
(*table)->print(thd, str, query_type);
1745617476

17457-
TABLE_LIST **end= table + non_const_tables;
17477+
TABLE_LIST **end= table + tables_to_print;
1745817478
for (TABLE_LIST **tbl= table + 1; tbl < end; tbl++)
1745917479
{
1746017480
TABLE_LIST *curr= *tbl;

0 commit comments

Comments
 (0)