Skip to content

Commit 115f082

Browse files
author
Sreeharsha Ramanavarapu
committed
Bug #23279858: MYSQLD GOT SIGNAL 11 ON SIMPLE SELECT
NAME_CONST QUERY ISSUE: ------ Using NAME_CONST with a non-constant negated expression as value can result in incorrect behavior. SOLUTION: --------- The problem can be avoided by checking whether the argument is a constant value. The fix is a backport of Bug#12735545.
1 parent 4de9d9c commit 115f082

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

mysql-test/r/func_misc.result

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,10 @@ DROP TABLE t1;
403403
#
404404
# End of tests
405405
#
406+
SELECT NAME_CONST('a', -(1 OR 2)) OR 1;
407+
ERROR HY000: Incorrect arguments to NAME_CONST
408+
SELECT NAME_CONST('a', -(1 AND 2)) OR 1;
409+
ERROR HY000: Incorrect arguments to NAME_CONST
410+
SELECT NAME_CONST('a', -(1)) OR 1;
411+
NAME_CONST('a', -(1)) OR 1
412+
1

mysql-test/t/func_misc.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,13 @@ DROP TABLE t1;
544544
--echo #
545545
--echo # End of tests
546546
--echo #
547+
548+
#
549+
# Bug#12735545 - PARSER STACK OVERFLOW WITH NAME_CONST
550+
# CONTAINING OR EXPRESSION
551+
#
552+
--error ER_WRONG_ARGUMENTS
553+
SELECT NAME_CONST('a', -(1 OR 2)) OR 1;
554+
--error ER_WRONG_ARGUMENTS
555+
SELECT NAME_CONST('a', -(1 AND 2)) OR 1;
556+
SELECT NAME_CONST('a', -(1)) OR 1;

sql/item.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,15 +1358,20 @@ bool Item_name_const::is_null()
13581358
Item_name_const::Item_name_const(Item *name_arg, Item *val):
13591359
value_item(val), name_item(name_arg)
13601360
{
1361+
/*
1362+
The value argument to NAME_CONST can only be a literal constant. Some extra
1363+
tests are needed to support a collation specificer and to handle negative
1364+
values.
1365+
*/
13611366
if (!(valid_args= name_item->basic_const_item() &&
13621367
(value_item->basic_const_item() ||
13631368
((value_item->type() == FUNC_ITEM) &&
13641369
((((Item_func *) value_item)->functype() ==
13651370
Item_func::COLLATE_FUNC) ||
13661371
((((Item_func *) value_item)->functype() ==
13671372
Item_func::NEG_FUNC) &&
1368-
(((Item_func *) value_item)->key_item()->type() !=
1369-
FUNC_ITEM)))))))
1373+
(((Item_func *)
1374+
value_item)->key_item()->basic_const_item())))))))
13701375
my_error(ER_WRONG_ARGUMENTS, MYF(0), "NAME_CONST");
13711376
Item::maybe_null= TRUE;
13721377
}

0 commit comments

Comments
 (0)