Commit 0d77e838 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp Committed by Tollef Fog Heen

Give VRT_re_match a sess* arg and report VRE errors using SLT_VCL_Error

instead of asserting.

Inspired by:	Patch from DocWilco
parent a8e77732
......@@ -67,7 +67,7 @@ VRT_re_fini(void *rep)
}
int
VRT_re_match(const char *s, void *re)
VRT_re_match(const struct sess *sp, const char *s, void *re)
{
vre_t *t;
int i;
......@@ -79,7 +79,8 @@ VRT_re_match(const char *s, void *re)
i = VRE_exec(t, s, strlen(s), 0, 0, NULL, 0);
if (i >= 0)
return (1);
assert(i == VRE_ERROR_NOMATCH);
if (i < VRE_ERROR_NOMATCH )
WSP(sp, SLT_VCL_error, "Regexp matching returned %d", i);
return (0);
}
......@@ -105,6 +106,10 @@ VRT_regsub(const struct sess *sp, int all, const char *str, void *re,
/* If it didn't match, we can return the original string */
if (i == VRE_ERROR_NOMATCH)
return(str);
if (i < VRE_ERROR_NOMATCH ) {
WSP(sp, SLT_VCL_error, "Regexp matching returned %d", i);
return(str);
}
u = WS_Reserve(sp->http->ws, 0);
res.e = res.b = b0 = sp->http->ws->f;
......@@ -135,6 +140,11 @@ VRT_regsub(const struct sess *sp, int all, const char *str, void *re,
break;
memset(&ovector, 0, sizeof(ovector));
i = VRE_exec(t, str, strlen(str), 0, 0, ovector, 30);
if (i < VRE_ERROR_NOMATCH ) {
WSP(sp, SLT_VCL_error,
"Regexp matching returned %d", i);
return(str);
}
} while (i != VRE_ERROR_NOMATCH);
/* Copy suffix to match */
......
......@@ -145,7 +145,7 @@ void VRT_acl_log(const struct sess *, const char *msg);
/* Regexp related */
void VRT_re_init(void **, const char *);
void VRT_re_fini(void *);
int VRT_re_match(const char *, void *re);
int VRT_re_match(const struct sess *sp, const char *, void *re);
const char *VRT_regsub(const struct sess *sp, int all, const char *,
void *, const char *);
......
......@@ -941,7 +941,7 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, enum var_type fmt)
re = vcc_regexp(tl);
ERRCHK(tl);
vcc_NextToken(tl);
bprintf(buf, "%sVRT_re_match(\v1, %s)", not, re);
bprintf(buf, "%sVRT_re_match(sp, \v1, %s)", not, re);
*e = vcc_expr_edit(BOOL, buf, *e, NULL);
return;
}
......
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