comparison src/core/ngx_regex.c @ 7983:d07456044b61

Core: added NGX_REGEX_MULTILINE for 3rd party modules. Notably, NAXSI is known to misuse ngx_regex_compile() with rc.options set to PCRE_CASELESS | PCRE_MULTILINE. With PCRE2 support, and notably binary compatibility changes, it is no longer possible to set PCRE[2]_MULTILINE option without using proper interface. To facilitate correct usage, this change adds the NGX_REGEX_MULTILINE option.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 25 Dec 2021 01:07:18 +0300
parents fbbb5ce52995
children 77d5c662f3d9
comparison
equal deleted inserted replaced
7982:fbbb5ce52995 7983:d07456044b61
157 157
158 if (rc->options & NGX_REGEX_CASELESS) { 158 if (rc->options & NGX_REGEX_CASELESS) {
159 options |= PCRE2_CASELESS; 159 options |= PCRE2_CASELESS;
160 } 160 }
161 161
162 if (rc->options & ~NGX_REGEX_CASELESS) { 162 if (rc->options & NGX_REGEX_MULTILINE) {
163 options |= PCRE2_MULTILINE;
164 }
165
166 if (rc->options & ~(NGX_REGEX_CASELESS|NGX_REGEX_MULTILINE)) {
163 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, 167 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
164 "regex \"%V\" compilation failed: invalid options", 168 "regex \"%V\" compilation failed: invalid options",
165 &rc->pattern) 169 &rc->pattern)
166 - rc->err.data; 170 - rc->err.data;
167 return NGX_ERROR; 171 return NGX_ERROR;
273 277
274 if (rc->options & NGX_REGEX_CASELESS) { 278 if (rc->options & NGX_REGEX_CASELESS) {
275 options |= PCRE_CASELESS; 279 options |= PCRE_CASELESS;
276 } 280 }
277 281
278 if (rc->options & ~NGX_REGEX_CASELESS) { 282 if (rc->options & NGX_REGEX_MULTILINE) {
283 options |= PCRE_MULTILINE;
284 }
285
286 if (rc->options & ~(NGX_REGEX_CASELESS|NGX_REGEX_MULTILINE)) {
279 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, 287 rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
280 "regex \"%V\" compilation failed: invalid options", 288 "regex \"%V\" compilation failed: invalid options",
281 &rc->pattern) 289 &rc->pattern)
282 - rc->err.data; 290 - rc->err.data;
283 return NGX_ERROR; 291 return NGX_ERROR;