[master] baa7e69 Improve the error messages for 'vcl N.N;'

Poul-Henning Kamp phk at FreeBSD.org
Mon Jan 15 09:32:06 UTC 2018


commit baa7e69d743d469287c7e36040aaf944bc23616a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jan 15 08:58:15 2018 +0000

    Improve the error messages for 'vcl N.N;'
    
    Some specialcasing is warranted to get sensible messages.
    
    Fixes #2532

diff --git a/bin/varnishtest/tests/v00049.vtc b/bin/varnishtest/tests/v00049.vtc
index 35a3efc..46cf468 100644
--- a/bin/varnishtest/tests/v00049.vtc
+++ b/bin/varnishtest/tests/v00049.vtc
@@ -15,3 +15,13 @@ varnish v1 -syntax 4.0 -errvcl "9.9 higher than the top level version" {
 	vcl 9.9;
 	backend b1 { .host = "127.0.0.1:8080"; }
 }
+
+varnish v1 -cliexpect {Don't play silly buggers with VCL version numbers} \
+	{vcl.inline t0 "vcl 4.00 ; backend b { .host = \"localhost\";} "}
+
+varnish v1 -cliexpect {Don't play silly buggers with VCL version numbers} \
+	{vcl.inline t1 "vcl 04.0 ; backend b { .host = \"localhost\";} "}
+
+varnish v1 -cliexpect {Expected 'vcl N.N;' found no semi-colon} \
+	{vcl.inline t2 "vcl 4.0  backend b { .host = \"localhost\";} "}
+
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index d0c040c..cff6c8f 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -310,7 +310,6 @@ void Resolve_Sockaddr(struct vcc *tl, const char *host, const char *defport,
 double vcc_TimeUnit(struct vcc *);
 void vcc_ByteVal(struct vcc *, double *);
 void vcc_NumVal(struct vcc *, double *, int *);
-double vcc_DoubleVal(struct vcc *tl);
 void vcc_Duration(struct vcc *tl, double *);
 unsigned vcc_UintVal(struct vcc *tl);
 
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index 94e6279..9652077 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -274,29 +274,50 @@ vcc_ParseFunction(struct vcc *tl)
 static void
 vcc_ParseVcl(struct vcc *tl)
 {
-	struct token *tok;
+	struct token *tok0, *tok1, *tok2;
 
 	assert(vcc_IdIs(tl->t, "vcl"));
+	tok0 = tl->t;
 	vcc_NextToken(tl);
-	tok = tl->t;
-	tok->src->syntax = vcc_DoubleVal(tl);
-	ERRCHK(tl);
-	if (tl->t->e - tok->b > 4) {
+
+	tok1 = tl->t;
+	Expect(tl, CNUM);
+	tok1->src->syntax = *tl->t->b - '0';
+	vcc_NextToken(tl);
+	Expect(tl, '.');
+	vcc_NextToken(tl);
+
+	Expect(tl, CNUM);
+	tok2 = tl->t;
+	tok1->src->syntax += .1 * (*tl->t->b - '0');
+	vcc_NextToken(tl);
+
+	if (tok1->e - tok1->b != 1 || tok2->e - tok2->b != 1) {
 		VSB_printf(tl->sb,
 		    "Don't play silly buggers with VCL version numbers\n");
-		vcc_ErrWhere2(tl, tok, tl->t);
+		vcc_ErrWhere2(tl, tok0, tl->t);
+		ERRCHK(tl);
+	}
+
+	if (tl->t->tok != ';') {
+		/* Special handling, because next token might be 'vcl'
+		 * in the built-in VCL, and that would give a very
+		 * confusing error message
+		 */
+		VSB_printf(tl->sb,
+		    "Expected 'vcl N.N;' found no semi-colon\n");
+		vcc_ErrWhere2(tl, tok0, tl->t);
 		ERRCHK(tl);
 	}
-	if (tl->syntax != 0.0 && tok->src->syntax > tl->syntax) {
+	vcc_NextToken(tl);
+	if (tl->syntax != 0.0 && tok1->src->syntax > tl->syntax) {
 		VSB_printf(tl->sb,
 		    "VCL version %.1f higher than"
 		    " the top level version %.1f\n",
-		    tok->src->syntax, tl->syntax);
-		vcc_ErrWhere2(tl, tok, tl->t);
+		    tok1->src->syntax, tl->syntax);
+		vcc_ErrWhere2(tl, tok0, tl->t);
 		ERRCHK(tl);
 	}
-	ExpectErr(tl, ';');
-	vcc_NextToken(tl);
 }
 
 /*--------------------------------------------------------------------
diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c
index a793c62..a2ae14d 100644
--- a/lib/libvcc/vcc_utils.c
+++ b/lib/libvcc/vcc_utils.c
@@ -344,7 +344,7 @@ vcc_NumVal(struct vcc *tl, double *d, int *frac)
 	vcc_NextToken(tl);
 }
 
-double
+static double
 vcc_DoubleVal(struct vcc *tl)
 {
 	double d;


More information about the varnish-commit mailing list