comparison src/core/ngx_regex.c @ 5824:e7f6991eca47

Core: ngx_regex_compile() error handling fixes. Now we actually return NGX_ERROR on errors, and provide an error string for memory allocation errors. Reported by Markus Linnala.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 08 Sep 2014 21:35:53 +0400
parents 6e1a48bcf915
children 457ec43dd8d5
comparison
equal deleted inserted replaced
5823:275e35d54626 5824:e7f6991eca47
147 return NGX_ERROR; 147 return NGX_ERROR;
148 } 148 }
149 149
150 rc->regex = ngx_pcalloc(rc->pool, sizeof(ngx_regex_t)); 150 rc->regex = ngx_pcalloc(rc->pool, sizeof(ngx_regex_t));
151 if (rc->regex == NULL) { 151 if (rc->regex == NULL) {
152 return NGX_ERROR; 152 goto nomem;
153 } 153 }
154 154
155 rc->regex->code = re; 155 rc->regex->code = re;
156 156
157 /* do not study at runtime */ 157 /* do not study at runtime */
158 158
159 if (ngx_pcre_studies != NULL) { 159 if (ngx_pcre_studies != NULL) {
160 elt = ngx_list_push(ngx_pcre_studies); 160 elt = ngx_list_push(ngx_pcre_studies);
161 if (elt == NULL) { 161 if (elt == NULL) {
162 return NGX_ERROR; 162 goto nomem;
163 } 163 }
164 164
165 elt->regex = rc->regex; 165 elt->regex = rc->regex;
166 elt->name = rc->pattern.data; 166 elt->name = rc->pattern.data;
167 } 167 }
202 202
203 failed: 203 failed:
204 204
205 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n) 205 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n)
206 - rc->err.data; 206 - rc->err.data;
207 return NGX_OK; 207 return NGX_ERROR;
208
209 nomem:
210
211 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
212 "regex \"%V\" compilation failed: no memory",
213 &rc->pattern)
214 - rc->err.data;
215 return NGX_ERROR;
208 } 216 }
209 217
210 218
211 ngx_int_t 219 ngx_int_t
212 ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log) 220 ngx_regex_exec_array(ngx_array_t *a, ngx_str_t *s, ngx_log_t *log)