Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there way to change MATCH_LIMIT settings for PCRE? #34

Open
hont512 opened this issue Aug 21, 2019 · 4 comments
Open

Is there way to change MATCH_LIMIT settings for PCRE? #34

hont512 opened this issue Aug 21, 2019 · 4 comments

Comments

@hont512
Copy link

hont512 commented Aug 21, 2019

Since LUA is often use in time-critical applications like web-servers, slow regexps could be fatal and MATCH_LIMIT settings should solve it.

I see nothing about it in lrexlib docs.

@shmuz
Copy link
Collaborator

shmuz commented Aug 21, 2019

It is supported.
One way is to supply the desired value of "execution flags" (see Lrexlib manual).
Another way is to specify flags in the pattern (a quote from PCRE manual follows):

A value for the match limit may also be supplied by an item at the start of a pattern of the form
(*LIMIT_MATCH=d) where d is a decimal number.

@hont512
Copy link
Author

hont512 commented Aug 21, 2019

Thank you very much

I dig in the flags way but didn't succeed since these flags take parameters for itself and "execution flags" field takes just bitwised flags

My thoughts were like this, but it is not correct:

local F = rex.flags()
local ef = F.EXTRA_MATCH_LIMIT | F.EXTRA_MATCH_LIMIT_RECURSION
local subject = "ABCD"
local pattern = "B.D"
rex.match(subject, pattern, 1, nil, ef, 10000, 15000)

@shmuz
Copy link
Collaborator

shmuz commented Aug 21, 2019

@hont512, you seem to be right. Lrexlib provides no means to user to modify pcre_extra struct that is passed as an argument to pcre_exec.

I'll try to study this issue more in depth (and it must take some time).

@shmuz
Copy link
Collaborator

shmuz commented May 9, 2021

@hont512
Adding extra flags and parameters would complicate the Lrexlib API (which is already pretty complicated).

So if the default built-in PCRE limits for MATCH_LIMIT and MATCH_LIMIT_RECURSION seem too big in some specific use case, they can be overridden by specifying (*LIMIT_MATCH=d)and/or (*LIMIT_RECURSION=d) in the pattern (where d is decimal number).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants