1 From: Date: August 29 2008 2:59pm
2 Subject: bzr commit into mysql-5.0 branch (ramil:2674) Bug#39021
3 List-Archive: http://lists.mysql.com/commits/52904
5 Message-Id: <200808291259.m7TCxLgl032452@localhost.localdomain>
7 #At file:///home/ram/mysql/b39021.5.0/
9 2674 Ramil Kalimullin 2008-08-29
10 Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
12 Problem: SELECT ... REGEXP BINARY NULL may lead to server crash/hang.
14 Fix: properly handle NULL regular expressions.
16 mysql-test/r/func_regexp.result
17 mysql-test/t/func_regexp.test
22 mysql-test/r/func_regexp.result
23 Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
25 mysql-test/t/func_regexp.test
26 Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
29 Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
30 - checking regular expressions' null_value
31 we tested it without a val_xxx() call before, which is wrong.
32 Now Item_func_regex::regcomp() returns -1 in the case
33 and allows to handle NULL expessions properly.
35 Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
36 - checking regular expressions' null_value
37 we tested it without a val_xxx() call before, which is wrong.
38 Now Item_func_regex::regcomp() returns -1 in the case
39 and allows to handle NULL expessions properly.
40 === modified file 'mysql-test/r/func_regexp.result'
41 --- a/mysql-test/r/func_regexp.result 2007-10-30 08:21:44 +0000
42 +++ b/mysql-test/r/func_regexp.result 2008-08-29 12:59:11 +0000
43 @@ -114,4 +114,16 @@ End of 4.1 tests
47 +SELECT '' REGEXP BINARY NULL;
48 +'' REGEXP BINARY NULL
50 +SELECT NULL REGEXP BINARY NULL;
51 +NULL REGEXP BINARY NULL
53 +SELECT 'A' REGEXP BINARY NULL;
54 +'A' REGEXP BINARY NULL
56 +SELECT "ABC" REGEXP BINARY NULL;
57 +"ABC" REGEXP BINARY NULL
61 === modified file 'mysql-test/t/func_regexp.test'
62 --- a/mysql-test/t/func_regexp.test 2007-10-30 08:21:44 +0000
63 +++ b/mysql-test/t/func_regexp.test 2008-08-29 12:59:11 +0000
64 @@ -64,4 +64,13 @@ drop table t1;
69 +# Bug #39021: SELECT REGEXP BINARY NULL never returns
72 +SELECT '' REGEXP BINARY NULL;
73 +SELECT NULL REGEXP BINARY NULL;
74 +SELECT 'A' REGEXP BINARY NULL;
75 +SELECT "ABC" REGEXP BINARY NULL;
77 --echo End of 5.0 tests
79 === modified file 'sql/item_cmpfunc.cc'
80 --- a/sql/item_cmpfunc.cc 2008-07-30 11:07:37 +0000
81 +++ b/sql/item_cmpfunc.cc 2008-08-29 12:59:11 +0000
82 @@ -4341,8 +4341,20 @@ void Item_func_like::cleanup()
87 -Item_func_regex::regcomp(bool send_error)
89 + @brief Compile regular expression.
91 + @param[in] send_error send error message if any.
93 + @details Make necessary character set conversion then
94 + compile regular expression passed in the args[1].
97 + @retval 1 error occurred.
98 + @retval -1 given null regular expression.
101 +int Item_func_regex::regcomp(bool send_error)
103 char buff[MAX_FIELD_WIDTH];
104 String tmp(buff,sizeof(buff),&my_charset_bin);
105 @@ -4350,12 +4362,12 @@ Item_func_regex::regcomp(bool send_error
108 if (args[1]->null_value)
114 if (!stringcmp(res, &prev_regexp))
117 prev_regexp.copy(*res);
120 @@ -4367,7 +4379,7 @@ Item_func_regex::regcomp(bool send_error
122 if (conv.copy(res->ptr(), res->length(), res->charset(),
123 regex_lib_charset, &dummy_errors))
129 @@ -4379,10 +4391,10 @@ Item_func_regex::regcomp(bool send_error
130 (void) my_regerror(error, &preg, buff, sizeof(buff));
131 my_error(ER_REGEXP_ERROR, MYF(0), buff);
142 @@ -4420,13 +4432,14 @@ Item_func_regex::fix_fields(THD *thd, It
143 const_item_cache=args[0]->const_item() && args[1]->const_item();
144 if (!regex_compiled && args[1]->const_item())
146 - if (args[1]->null_value)
147 + int comp_res= regcomp(TRUE);
148 + if (comp_res == -1)
149 { // Will always return NULL
155 + else if (comp_res) // Error occurred
158 maybe_null= args[0]->maybe_null;
160 === modified file 'sql/item_cmpfunc.h'
161 --- a/sql/item_cmpfunc.h 2008-01-23 15:03:58 +0000
162 +++ b/sql/item_cmpfunc.h 2008-08-29 12:59:11 +0000
163 @@ -1323,7 +1323,7 @@ class Item_func_regex :public Item_bool_
164 CHARSET_INFO *regex_lib_charset;
167 - bool regcomp(bool send_error);
168 + int regcomp(bool send_error);
170 Item_func_regex(Item *a,Item *b) :Item_bool_func(a,b),
171 regex_compiled(0),regex_is_const(0) {}