Commit 2b7b320c authored by Geoff Simmons's avatar Geoff Simmons

eliminate some repetition in the range checking for match() options

parent 2ab4f12c
......@@ -445,28 +445,20 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
if (mctx_call->priv == NULL) {
pcre2_match_context *mctx;
/* XXX DRY */
if (match_limit < 0 || match_limit > UINT32_MAX) {
VERR(ctx, "match_limit (%lld) out of range in "
"%s.match() (must be >= 0 and <= %" PRIu32 ")",
(long long)match_limit, regex->vcl_name,
UINT32_MAX);
return 0;
}
if (offset_limit < 0 || offset_limit > UINT32_MAX) {
VERR(ctx, "offset_limit (%lld) out of range in "
"%s.match() (must be >= 0 and <= %" PRIu32 ")",
(long long)offset_limit, regex->vcl_name,
UINT32_MAX);
return 0;
}
if (recursion_limit < 0 || recursion_limit > UINT32_MAX) {
VERR(ctx, "recursion_limit (%lld) out of range in "
"%s.match() (must be >= 0 and <= %" PRIu32 ")",
(long long)recursion_limit, regex->vcl_name,
UINT32_MAX);
return 0;
}
#define CHECK_RANGE(limit) do { \
if ((limit) < 0 || (limit) > UINT32_MAX) { \
VERR(ctx, #limit " (%lld) out of range in " \
"%s.match() (must be >= 0 and <= %" \
PRIu32 ")", (long long)(limit), \
regex->vcl_name, UINT32_MAX); \
return 0; \
} \
} while(0)
CHECK_RANGE(match_limit);
CHECK_RANGE(offset_limit);
CHECK_RANGE(recursion_limit);
#undef CHECK_RANGE
if ((mctx = pcre2_match_context_create(NULL)) == NULL) {
VERRNOMEM(ctx, "creating match context in %s.match()",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment