[3.0] 0d77e83 Give VRT_re_match a sess* arg and report VRE errors using SLT_VCL_Error instead of asserting.

Tollef Fog Heen tfheen at varnish-cache.org
Mon Apr 16 10:20:33 CEST 2012


commit 0d77e8383c08895d98b04a84e6619f7a0cc638dc
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Sep 22 11:48:16 2011 +0000

    Give VRT_re_match a sess* arg and report VRE errors using SLT_VCL_Error
    instead of asserting.
    
    Inspired by:	Patch from DocWilco

diff --git a/bin/varnishd/cache_vrt_re.c b/bin/varnishd/cache_vrt_re.c
index 8e1218a..a02b6ff 100644
--- a/bin/varnishd/cache_vrt_re.c
+++ b/bin/varnishd/cache_vrt_re.c
@@ -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 */
diff --git a/include/vrt.h b/include/vrt.h
index 9f0228f..72c4cfe 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -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 *);
 
diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c
index 3883dd2..1f1c274 100644
--- a/lib/libvcl/vcc_expr.c
+++ b/lib/libvcl/vcc_expr.c
@@ -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;
 	}



More information about the varnish-commit mailing list