diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2021-12-25 01:07:16 +0300 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2021-12-25 01:07:16 +0300 |
commit | 931acbf5bcd550af8613d131f4ba49e22e909efb (patch) | |
tree | 546ca4eff7cdd6918e2efb5283eb60c96c0f30c5 /src/core/ngx_regex.c | |
parent | c6fec0b027569a4e0b1d8aaee7dea0f2e4d6052b (diff) | |
download | nginx-931acbf5bcd550af8613d131f4ba49e22e909efb.tar.gz nginx-931acbf5bcd550af8613d131f4ba49e22e909efb.zip |
PCRE2 and PCRE binary compatibility.
With this change, dynamic modules using nginx regex interface can be used
regardless of the variant of the PCRE library nginx was compiled with.
If a module is compiled with different PCRE library variant, in case of
ngx_regex_exec() errors it will report wrong function name in error
messages. This is believed to be tolerable, given that fixing this will
require interface changes.
Diffstat (limited to 'src/core/ngx_regex.c')
-rw-r--r-- | src/core/ngx_regex.c | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/core/ngx_regex.c b/src/core/ngx_regex.c index 5ae4f780b..991728b27 100644 --- a/src/core/ngx_regex.c +++ b/src/core/ngx_regex.c @@ -118,6 +118,7 @@ ngx_regex_compile(ngx_regex_compile_t *rc) char *p; u_char errstr[128]; size_t erroff; + uint32_t options; pcre2_code *re; ngx_regex_elt_t *elt; pcre2_general_context *gctx; @@ -152,11 +153,24 @@ ngx_regex_compile(ngx_regex_compile_t *rc) ngx_regex_malloc_done(); } + options = 0; + + if (rc->options & NGX_REGEX_CASELESS) { + options |= PCRE2_CASELESS; + } + + if (rc->options & ~NGX_REGEX_CASELESS) { + rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, + "regex \"%V\" compilation failed: invalid options", + &rc->pattern) + - rc->err.data; + return NGX_ERROR; + } + ngx_regex_malloc_init(rc->pool); - re = pcre2_compile(rc->pattern.data, rc->pattern.len, - (uint32_t) rc->options, &errcode, &erroff, - ngx_regex_compile_context); + re = pcre2_compile(rc->pattern.data, rc->pattern.len, options, + &errcode, &erroff, ngx_regex_compile_context); /* ensure that there is no current pool */ ngx_regex_malloc_done(); @@ -252,11 +266,26 @@ ngx_regex_compile(ngx_regex_compile_t *rc) char *p; pcre *re; const char *errstr; + ngx_uint_t options; ngx_regex_elt_t *elt; + options = 0; + + if (rc->options & NGX_REGEX_CASELESS) { + options |= PCRE_CASELESS; + } + + if (rc->options & ~NGX_REGEX_CASELESS) { + rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, + "regex \"%V\" compilation failed: invalid options", + &rc->pattern) + - rc->err.data; + return NGX_ERROR; + } + ngx_regex_malloc_init(rc->pool); - re = pcre_compile((const char *) rc->pattern.data, (int) rc->options, + re = pcre_compile((const char *) rc->pattern.data, (int) options, &errstr, &erroff, NULL); /* ensure that there is no current pool */ @@ -413,6 +442,15 @@ failed: return rc; } +#else + +ngx_int_t +ngx_regex_exec(ngx_regex_t *re, ngx_str_t *s, int *captures, ngx_uint_t size) +{ + return pcre_exec(re->code, re->extra, (const char *) s->data, s->len, + 0, 0, captures, size); +} + #endif |