[master] 54800eb Also check weekdays in VTIM_parse(), once we have the day number it's just another division.

Poul-Henning Kamp phk at FreeBSD.org
Mon Feb 23 16:48:39 CET 2015


commit 54800eb941e0f822aa6c8c136b9556094e2e0855
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Feb 23 15:48:01 2015 +0000

    Also check weekdays in VTIM_parse(), once we have the day number
    it's just another division.
    
    Fix m00020 to use valid weekdays

diff --git a/bin/varnishtest/tests/m00020.vtc b/bin/varnishtest/tests/m00020.vtc
index 3611cc4..2ac50f8 100644
--- a/bin/varnishtest/tests/m00020.vtc
+++ b/bin/varnishtest/tests/m00020.vtc
@@ -22,7 +22,7 @@ client c1 {
 	txreq -hdr "X-Date: Mon, 20 Dec 2010 00:00:00 GMT"
 	rxresp
 	expect resp.http.x-past == 1
-	txreq -hdr "X-Date: Monday, 20-Dec-30 00:00:00 GMT"
+	txreq -hdr "X-Date: Monday, 23-Dec-30 00:00:00 GMT"
 	rxresp
 	expect resp.http.x-future == 1
 	txreq -hdr "X-Date: Mon Dec 20 00:00:00 2010"
diff --git a/bin/varnishtest/tests/r01665.vtc b/bin/varnishtest/tests/r01665.vtc
index 6d645d2..3dc7530 100644
--- a/bin/varnishtest/tests/r01665.vtc
+++ b/bin/varnishtest/tests/r01665.vtc
@@ -1,21 +1,19 @@
 varnishtest "Ticket 1665 regression test: wrong behavior of timeout_req"
 
 server s1 {
-        rxreq
-       	txresp
+	rxreq
+	txresp
 } -start
 
 varnish v1 -vcl+backend {
 } -start
 
 client c1 {
-		delay 1
-		send "GET "
-		delay 1.8
-		send "/bar\n\n "
-		delay 0.1
-		send "GET"     
-		rxresp
+	delay 1
+	send "GET "
+	delay 1.8
+	send "/bar\n\n "
+	delay 0.1
+	send "GET"
+	rxresp
 } -run
-
-		
diff --git a/lib/libvarnish/vtim.c b/lib/libvarnish/vtim.c
index 96691d0..a7e4c6e 100644
--- a/lib/libvarnish/vtim.c
+++ b/lib/libvarnish/vtim.c
@@ -209,7 +209,7 @@ double
 VTIM_parse(const char *p)
 {
 	double t;
-	int month = 0, year = 0, weekday = 0, mday = 0;
+	int month = 0, year = 0, weekday = -1, mday = 0;
 	int hour = 0, min = 0, sec = 0;
 	int d, leap;
 
@@ -340,6 +340,14 @@ VTIM_parse(const char *p)
 
 	d += ((year-1) / 400) - 4;	/* And one more every 400 years */
 
+	/*
+	 * Now check weekday, if we have one.
+	 * 6 is because 2000-01-01 was a saturday.
+	 * 10000 is to make sure the modulus argument is always positive
+	 */
+	if (weekday != -1 && (d + 6 + 7 * 10000) % 7 != weekday)
+		FAIL();
+
 	t += d * 86400.;
 
 	t += 10957. * 86400.;		/* 10957 days frm UNIX epoch to y2000 */



More information about the varnish-commit mailing list