[master] 23705c4 Use VRT_fail in case silly HTTP status numbers are set, and test that.
Poul-Henning Kamp
phk at FreeBSD.org
Tue Feb 7 12:06:05 CET 2017
commit 23705c43713e7cff1d87e28702ed92a56650f6bb
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Feb 7 11:04:51 2017 +0000
Use VRT_fail in case silly HTTP status numbers are set, and test that.
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index d731f6e..a603ecc 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -97,17 +97,14 @@ VRT_l_##obj##_status(VRT_CTX, long num) \
\
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
CHECK_OBJ_NOTNULL(ctx->http_##obj, HTTP_MAGIC); \
- if (num > 65535) { \
- VSLb(ctx->vsl, SLT_VCL_Error, \
- "%s.status > 65535", #obj); \
- WS_MarkOverflow(ctx->http_##obj->ws); \
- } else if ((num % 1000) < 100) { \
- VSLb(ctx->vsl, SLT_VCL_Error, \
- "illegal %s.status (..0##)", #obj); \
- WS_MarkOverflow(ctx->http_##obj->ws); \
- } else { \
+ if (num < 0) \
+ VRT_fail(ctx, "%s.status (%ld) is negative", #obj, num); \
+ else if (num > 65535) \
+ VRT_fail(ctx, "%s.status (%ld) > 65535", #obj, num); \
+ else if ((num % 1000) < 100) \
+ VRT_fail(ctx, "illegal %s.status (%ld) (..0##)", #obj, num); \
+ else \
http_SetStatus(ctx->http_##obj, (uint16_t)num); \
- } \
}
#define VRT_STATUS_R(obj) \
diff --git a/bin/varnishtest/tests/v00050.vtc b/bin/varnishtest/tests/v00050.vtc
index c880c7b..f4ab7ac 100644
--- a/bin/varnishtest/tests/v00050.vtc
+++ b/bin/varnishtest/tests/v00050.vtc
@@ -91,6 +91,15 @@ varnish v1 -vcl+backend {
return (synth(400));
}
}
+ if (req.http.huge == "yes") {
+ set resp.status = 65536;
+ }
+ if (req.http.small == "yes") {
+ set resp.status = 99;
+ }
+ if (req.http.negative == "yes") {
+ set resp.status = -200;
+ }
}
sub vcl_recv {
@@ -100,6 +109,9 @@ varnish v1 -vcl+backend {
}
sub vcl_synth {
+ if (resp.reason == "VCL failed") {
+ return (deliver);
+ }
std.log("synth " + resp.status + " " + resp.reason);
if (resp.status != 22301) {
set resp.status = 501;
@@ -148,10 +160,35 @@ client c1 {
rxresp
expect resp.status == 302
expect resp.reason == "Wrong Postcode"
-}
+} -run
+
+logexpect l1 -v v1 {
+ expect * * VCL_Error "illegal resp.status .99. ...0##."
+ expect * * VCL_Error "resp.status .65536. > 65535"
+ expect * * VCL_Error "resp.status .-200. is negative"
+} -start
-client c1 -run
+client c1 {
+ txreq -url "/a" -hdr "Small: yes"
+ rxresp
+ expect resp.status == 503
+ expect resp.reason == "VCL failed"
+
+ expect_close
+} -run
+
+client c1 {
+ txreq -url "/a" -hdr "Huge: yes"
+ rxresp
+ expect resp.status == 503
+ expect resp.reason == "VCL failed"
+} -run
-server s1 -wait
+client c1 {
+ txreq -url "/a" -hdr "Negative: yes"
+ rxresp
+ expect resp.status == 503
+ expect resp.reason == "VCL failed"
+} -run
-varnish v1 -stop
+logexpect l1 -wait
More information about the varnish-commit
mailing list