Skip to content

Commit 19db56b

Browse files
baluschdoujiang24
authored andcommitted
bugfix: we should ignore match limit in DFA mode.
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 b989a8a commit 19db56b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/ngx_stream_lua_regex.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,10 @@ ngx_stream_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
321321

322322
#endif /* LUA_HAVE_PCRE_JIT */
323323

324-
if (sd && lmcf && lmcf->regex_match_limit > 0) {
324+
if (sd
325+
&& lmcf && lmcf->regex_match_limit > 0
326+
&& !(flags & NGX_LUA_RE_MODE_DFA))
327+
{
325328
sd->flags |= PCRE_EXTRA_MATCH_LIMIT;
326329
sd->match_limit = lmcf->regex_match_limit;
327330
}

t/120-re-find.t

+28
Original file line numberDiff line numberDiff line change
@@ -768,3 +768,31 @@ not matched!
768768
not matched!
769769
--- no_error_log
770770
[error]
771+
772+
773+
774+
=== TEST 31: ignore match limit in DFA mode
775+
--- stream_config
776+
lua_regex_match_limit 1;
777+
--- stream_server_config
778+
content_by_lua_block {
779+
local s = "This is <something> <something else> <something further> no more"
780+
local from, to, err = ngx.re.find(s, "<.*>", "d")
781+
if from then
782+
ngx.say("from: ", from)
783+
ngx.say("to: ", to)
784+
ngx.say("matched: ", string.sub(s, from, to))
785+
else
786+
if err then
787+
ngx.say("error: ", err)
788+
return
789+
end
790+
ngx.say("not matched!")
791+
end
792+
}
793+
--- stream_response
794+
from: 9
795+
to: 56
796+
matched: <something> <something else> <something further>
797+
--- no_error_log
798+
[error]

0 commit comments

Comments
 (0)