Skip to content

Commit 5425d6d

Browse files
authored
bugfix: we should ignore match limit in DFA mode. (#1924)
lua_regex_match_limit takes effect globally for all regexes used in ngx.re api. However, the match_limit field of pcre_extra block is not supported in pcre_dfa_exec()(so does match_limit_recursion), because it is meaningless in DFA matching. And pcre_dfa_exec() will return -18(PCRE_ERROR_DFA_UMLIMIT) when the directive is used. Here we just ignore the directive in DFA mode.
1 parent fef2581 commit 5425d6d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/ngx_http_lua_regex.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,10 @@ ngx_http_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
311311

312312
#endif /* LUA_HAVE_PCRE_JIT */
313313

314-
if (sd && lmcf && lmcf->regex_match_limit > 0) {
314+
if (sd
315+
&& lmcf && lmcf->regex_match_limit > 0
316+
&& !(flags & NGX_LUA_RE_MODE_DFA))
317+
{
315318
sd->flags |= PCRE_EXTRA_MATCH_LIMIT;
316319
sd->match_limit = lmcf->regex_match_limit;
317320
}

t/120-re-find.t

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,3 +917,35 @@ to: 4
917917
pos: 5
918918
--- no_error_log
919919
[error]
920+
921+
922+
923+
=== TEST 32: ignore match limit in DFA mode
924+
--- http_config
925+
lua_regex_match_limit 1;
926+
--- config
927+
location /re {
928+
content_by_lua_block {
929+
local s = "This is <something> <something else> <something further> no more"
930+
local from, to, err = ngx.re.find(s, "<.*>", "d")
931+
if from then
932+
ngx.say("from: ", from)
933+
ngx.say("to: ", to)
934+
ngx.say("matched: ", string.sub(s, from, to))
935+
else
936+
if err then
937+
ngx.say("error: ", err)
938+
return
939+
end
940+
ngx.say("not matched!")
941+
end
942+
}
943+
}
944+
--- request
945+
GET /re
946+
--- response_body
947+
from: 9
948+
to: 56
949+
matched: <something> <something else> <something further>
950+
--- no_error_log
951+
[error]

0 commit comments

Comments
 (0)