From a2850a2f5323bfe8eaae17746c88986cee37fc76 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 17 Jan 2011 12:30:22 +0300 Subject: Bug#59149 valgrind warnings with "like .. escape .." function Problem: when processing a query like: SELECT '' LIKE '1' ESCAPE COUNT(1); escape_item->val_str() was never executed and the "escape" class member stayed initialized, which led to valgrind uninitialized memory error. Note, a query with some tables in "FROM" clause returns ER_WRONG_ARGUMENTS in the same situation: SELECT '' LIKE '1' ESCAPE COUNT(1) FROM t1; ERROR 1210 (HY000): Incorrect arguments to ESCAPE Fix: disallowing using aggregate functions in ESCAPE clause, even if there are no tables used. There is no much use of that anyway. --- mysql-test/r/func_like.result | 5 +++++ mysql-test/t/func_like.test | 5 +++++ sql/item_sum.h | 1 + 3 files changed, 11 insertions(+) diff --git a/mysql-test/r/func_like.result b/mysql-test/r/func_like.result index 21da211160b..76174982e8e 100644 --- a/mysql-test/r/func_like.result +++ b/mysql-test/r/func_like.result @@ -182,4 +182,9 @@ INSERT INTO t2 VALUES (1), (2), (3); SELECT 1 FROM t2 JOIN t1 ON 1 LIKE a GROUP BY a; 1 DROP TABLE t1, t2; +# +# Bug#59149 valgrind warnings with "like .. escape .." function +# +SELECT '' LIKE '1' ESCAPE COUNT(1); +ERROR HY000: Incorrect arguments to ESCAPE End of 5.1 tests diff --git a/mysql-test/t/func_like.test b/mysql-test/t/func_like.test index 1204d04d9a0..f1fe52274b2 100644 --- a/mysql-test/t/func_like.test +++ b/mysql-test/t/func_like.test @@ -126,5 +126,10 @@ INSERT INTO t2 VALUES (1), (2), (3); SELECT 1 FROM t2 JOIN t1 ON 1 LIKE a GROUP BY a; DROP TABLE t1, t2; +--echo # +--echo # Bug#59149 valgrind warnings with "like .. escape .." function +--echo # +--error ER_WRONG_ARGUMENTS +SELECT '' LIKE '1' ESCAPE COUNT(1); --echo End of 5.1 tests diff --git a/sql/item_sum.h b/sql/item_sum.h index de988c196ec..f8819d63bf4 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -339,6 +339,7 @@ public: forced_const= TRUE; } virtual bool const_item() const { return forced_const; } + virtual bool const_during_execution() const { return false; } virtual void print(String *str, enum_query_type query_type); void fix_num_length_and_dec(); -- cgit v1.2.1