From d830cc9e0839cf24d5954c4dddeb267d55390a51 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 29 Sep 2008 08:12:19 +0000 Subject: [PATCH] When a VCL subroutine does not terminate in an action, the compiled code needs to explicitly set a return value of zero to say so. Possibly fix for: #339 git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3236 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- .../bin/varnishtest/tests/v00015.vtc | 29 +++++++++++++++++++ varnish-cache/lib/libvcl/vcc_parse.c | 13 +++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 varnish-cache/bin/varnishtest/tests/v00015.vtc diff --git a/varnish-cache/bin/varnishtest/tests/v00015.vtc b/varnish-cache/bin/varnishtest/tests/v00015.vtc new file mode 100644 index 00000000..c60bb451 --- /dev/null +++ b/varnish-cache/bin/varnishtest/tests/v00015.vtc @@ -0,0 +1,29 @@ +# $Id$ + +test "Check function calls with no action return" + +server s1 { + rxreq + expect req.url == "/" + expect req.http.foobar == "snafu" + txresp -body "slash" +} -start + +varnish v1 -vcl+backend { + + sub vcl_recv { + call some_subr; + } + + sub some_subr { + set req.http.foobar = "snafu"; + } + +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run + diff --git a/varnish-cache/lib/libvcl/vcc_parse.c b/varnish-cache/lib/libvcl/vcc_parse.c index 848cfaae..5f8e4d6e 100644 --- a/varnish-cache/lib/libvcl/vcc_parse.c +++ b/varnish-cache/lib/libvcl/vcc_parse.c @@ -526,22 +526,31 @@ Function(struct tokenlist *tl) vcc_AddRef(tl, tl->t, R_FUNC); } tl->curproc = tl->mprocs[m]; + Fb(tl, 1, " /* ... from "); + vcc_Coord(tl, tl->fb, NULL); + Fb(tl, 0, " */\n"); } else { tl->fb = tl->fc; tl->curproc = vcc_AddProc(tl, tl->t); vcc_AddDef(tl, tl->t, R_FUNC); Fh(tl, 0, "static int VGC_function_%.*s (struct sess *sp);\n", PF(tl->t)); - Fc(tl, 1, "static int\n"); + Fc(tl, 1, "\nstatic int\n"); Fc(tl, 1, "VGC_function_%.*s (struct sess *sp)\n", PF(tl->t)); } vcc_NextToken(tl); tl->indent += INDENT; Fb(tl, 1, "{\n"); L(tl, Compound(tl)); + if (m == -1) { + /* + * non-method subroutines must have an explicit non-action + * return in case they just fall through the bottom. + */ + Fb(tl, 1, " return(0);\n"); + } Fb(tl, 1, "}\n"); tl->indent -= INDENT; - Fb(tl, 0, "\n"); tl->fb = NULL; tl->curproc = NULL; } -- 2.39.5