]> git.pld-linux.org Git - packages/mysql.git/blob - mysql-bug-39021.patch
- http://lists.mysql.com/commits/52904?f=plain
[packages/mysql.git] / mysql-bug-39021.patch
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
4 X-Bug: 39021
5 Message-Id: <200808291259.m7TCxLgl032452@localhost.localdomain>
6
7 #At file:///home/ram/mysql/b39021.5.0/
8
9  2674 Ramil Kalimullin  2008-08-29
10       Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
11       
12       Problem: SELECT ... REGEXP BINARY NULL may lead to server crash/hang.
13       
14       Fix: properly handle NULL regular expressions.
15 modified:
16   mysql-test/r/func_regexp.result
17   mysql-test/t/func_regexp.test
18   sql/item_cmpfunc.cc
19   sql/item_cmpfunc.h
20
21 per-file messages:
22   mysql-test/r/func_regexp.result
23     Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
24       - test result.
25   mysql-test/t/func_regexp.test
26     Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
27       - test case.
28   sql/item_cmpfunc.cc
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.
34   sql/item_cmpfunc.h
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
44  SELECT 1 REGEXP NULL;
45  1 REGEXP NULL
46  NULL
47 +SELECT '' REGEXP BINARY NULL;
48 +'' REGEXP BINARY NULL
49 +NULL
50 +SELECT NULL REGEXP BINARY NULL;
51 +NULL REGEXP BINARY NULL
52 +NULL
53 +SELECT 'A' REGEXP BINARY NULL;
54 +'A' REGEXP BINARY NULL
55 +NULL
56 +SELECT "ABC" REGEXP BINARY NULL;
57 +"ABC" REGEXP BINARY NULL
58 +NULL
59  End of 5.0 tests
60
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;
65  
66  SELECT 1 REGEXP NULL;
67  
68 +#
69 +# Bug #39021: SELECT REGEXP BINARY NULL never returns
70 +#
71 +
72 +SELECT '' REGEXP BINARY NULL;
73 +SELECT NULL REGEXP BINARY NULL;
74 +SELECT 'A' REGEXP BINARY NULL;
75 +SELECT "ABC" REGEXP BINARY NULL;
76 +
77  --echo End of 5.0 tests
78
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()
83  
84  #ifdef USE_REGEX
85  
86 -bool
87 -Item_func_regex::regcomp(bool send_error)
88 +/**
89 +  @brief Compile regular expression.
90 +
91 +  @param[in]    send_error     send error message if any.
92 +
93 +  @details Make necessary character set conversion then 
94 +  compile regular expression passed in the args[1].
95 +
96 +  @retval    0     success.
97 +  @retval    1     error occurred.
98 +  @retval   -1     given null regular expression.
99 + */
100 +
101 +int Item_func_regex::regcomp(bool send_error)
102  {
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
106    int error;
107  
108    if (args[1]->null_value)
109 -    return TRUE;
110 +    return -1;
111  
112    if (regex_compiled)
113    {
114      if (!stringcmp(res, &prev_regexp))
115 -      return FALSE;
116 +      return 0;
117      prev_regexp.copy(*res);
118      my_regfree(&preg);
119      regex_compiled= 0;
120 @@ -4367,7 +4379,7 @@ Item_func_regex::regcomp(bool send_error
121      uint dummy_errors;
122      if (conv.copy(res->ptr(), res->length(), res->charset(),
123                    regex_lib_charset, &dummy_errors))
124 -      return TRUE;
125 +      return 1;
126      res= &conv;
127    }
128  
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);
132      }
133 -    return TRUE;
134 +    return 1;
135    }
136    regex_compiled= 1;
137 -  return FALSE;
138 +  return 0;
139  }
140  
141  
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())
145    {
146 -    if (args[1]->null_value)
147 +    int comp_res= regcomp(TRUE);
148 +    if (comp_res == -1)
149      {                                          // Will always return NULL
150        maybe_null=1;
151        fixed= 1;
152        return FALSE;
153      }
154 -    if (regcomp(TRUE))
155 +    else if (comp_res)                          // Error occurred
156        return TRUE;
157      regex_is_const= 1;
158      maybe_null= args[0]->maybe_null;
159
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;
165    int regex_lib_flags;
166    String conv;
167 -  bool regcomp(bool send_error);
168 +  int regcomp(bool send_error);
169  public:
170    Item_func_regex(Item *a,Item *b) :Item_bool_func(a,b),
171      regex_compiled(0),regex_is_const(0) {}
172
This page took 0.124353 seconds and 4 git commands to generate.