[master] ea19d46 Fix the max-value of the vfp->bytes() length argument.

Poul-Henning Kamp phk at project.varnish-software.com
Sat Jan 22 09:57:03 CET 2011


commit ea19d46387e62ef3bb4015580bee99d5e75a3930
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sat Jan 22 08:55:51 2011 +0000

    Fix the max-value of the vfp->bytes() length argument.
    
    Add a vef_read() function which implements the esi_syntax&8 bit,
    it is too late to do it when we call VEP_parse().

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 466b0aa..b3b49d9 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -214,7 +214,7 @@ struct dstat {
 /* Fetch processors --------------------------------------------------*/
 
 typedef void vfp_begin_f(struct sess *, size_t );
-typedef int vfp_bytes_f(struct sess *, struct http_conn *, size_t);
+typedef int vfp_bytes_f(struct sess *, struct http_conn *, ssize_t);
 typedef int vfp_end_f(struct sess *sp);
 
 struct vfp {
diff --git a/bin/varnishd/cache_esi_fetch.c b/bin/varnishd/cache_esi_fetch.c
index 38102bf..96ae56f 100644
--- a/bin/varnishd/cache_esi_fetch.c
+++ b/bin/varnishd/cache_esi_fetch.c
@@ -43,13 +43,35 @@ SVNID("$Id")
 #include "stevedore.h"
 
 /*---------------------------------------------------------------------
+ * Read some bytes.
+ *
+ * If the esi_syntax&8 bit is set, we read only a couple of bytes at
+ * a time, in order to stress the parse/pending/callback code.
+ */
+
+static ssize_t
+vef_read(struct http_conn *htc, void *buf, ssize_t buflen, ssize_t bytes)
+{
+	ssize_t d;
+
+	if (buflen < bytes)
+		bytes = buflen;
+	if (params->esi_syntax & 0x8) {
+		d = (random() & 3) + 1;
+		if (d < bytes)
+			bytes = d;
+	}
+	return (HTC_Read(htc, buf, bytes));
+}
+
+/*---------------------------------------------------------------------
  * We receive a ungzip'ed object, and want to store it ungzip'ed.
  */
 
 static int __match_proto__()
-vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes)
+vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 {
-	ssize_t l, w;
+	ssize_t w;
 	struct storage *st;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
@@ -58,10 +80,8 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes)
 		if (FetchStorage(sp))
 			return (-1);
 		st = sp->wrk->storage;
-		l = st->space - st->len;
-		if (l > bytes)
-			l = bytes;
-		w = HTC_Read(htc, st->ptr + st->len, l);
+		w = vef_read(htc,
+		    st->ptr + st->len, st->space - st->len, bytes);
 		if (w <= 0)
 			return (w);
 		VEP_parse(sp, (const char *)st->ptr + st->len, w);
@@ -77,10 +97,10 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes)
  */
 
 static int __match_proto__()
-vfp_esi_bytes_gu(struct sess *sp, struct http_conn *htc, size_t bytes)
+vfp_esi_bytes_gu(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 {
 	struct vgz *vg;
-	ssize_t l, w;
+	ssize_t w;
 	uint8_t	ibuf[1024 * params->gzip_stack_buffer];
 	int i;
 	size_t dl;
@@ -91,10 +111,7 @@ vfp_esi_bytes_gu(struct sess *sp, struct http_conn *htc, size_t bytes)
 
 	while (bytes > 0) {
 		if (VGZ_IbufEmpty(vg) && bytes > 0) {
-			l = sizeof ibuf;
-			if (l > bytes)
-				l = bytes;
-			w = HTC_Read(htc, ibuf, l);
+			w = vef_read(htc, ibuf, sizeof ibuf, bytes);
 			if (w <= 0)
 				return (w);
 			VGZ_Ibuf(vg, ibuf, w);
@@ -145,6 +162,11 @@ vfp_vep_callback(const struct sess *sp, ssize_t l, enum vgz_flag flg)
 		return (vef->tot);
 	}
 
+	/* This would just give Z_BUF_ERROR anyway */
+	if (l == 0 && flg == VGZ_NORMAL)
+		return (vef->tot);
+
+printf("xxC %jd\n", l);
 	VGZ_Ibuf(vef->vgz, vef->bufp, l);
 	do {
 		if (VGZ_ObufStorage(sp, vef->vgz)) {
@@ -165,9 +187,9 @@ vfp_vep_callback(const struct sess *sp, ssize_t l, enum vgz_flag flg)
 }
 
 static int __match_proto__()
-vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, size_t bytes)
+vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 {
-	ssize_t l, w;
+	ssize_t w;
 	char ibuf[1024 * params->gzip_stack_buffer];
 	struct vef_priv *vef;
 
@@ -176,19 +198,18 @@ vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, size_t bytes)
 	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
 
 	while (bytes > 0) {
-		l = sizeof ibuf;
-		if (l > bytes)
-			l = bytes;
-		w = HTC_Read(htc, ibuf, l);
+		w = vef_read(htc, ibuf, sizeof ibuf, bytes);
 		if (w <= 0)
 			return (w);
 		bytes -= w;
 		vef->bufp = ibuf;
-		VEP_parse(sp, ibuf, l);
+printf("xxP %jd\n", w);
+		VEP_parse(sp, ibuf, w);
 		if (vef->error) {
 			errno = vef->error;
 			return (-1);
 		}
+		assert(vef->bufp == ibuf + w);
 	}
 	return (1);
 }
@@ -234,7 +255,7 @@ vfp_esi_begin(struct sess *sp, size_t estimate)
 }
 
 static int __match_proto__()
-vfp_esi_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
+vfp_esi_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 {
 	int i;
 
diff --git a/bin/varnishd/cache_esi_parse.c b/bin/varnishd/cache_esi_parse.c
index ed04ec1..93522d2 100644
--- a/bin/varnishd/cache_esi_parse.c
+++ b/bin/varnishd/cache_esi_parse.c
@@ -539,8 +539,8 @@ vep_do_include(struct vep_state *vep, enum dowhat what)
  * NB: the state-machine.  Please maintain it along with the code.
  */
 
-static void
-vep_parse_int(const struct sess *sp, const char *p, size_t l)
+void
+VEP_parse(const struct sess *sp, const char *p, size_t l)
 {
 	struct vep_state *vep;
 	const char *e;
@@ -965,22 +965,6 @@ vep_parse_int(const struct sess *sp, const char *p, size_t l)
 		vep_mark_pending(vep, p);
 }
 
-void
-VEP_parse(const struct sess *sp, const char *p, size_t w)
-{
-	ssize_t l, d;
-
-	if (params->esi_syntax & 0x8) {
-		for (l = 0; l < w; l += d)  {
-			d = (random() & 3) + 1;
-			if (l + d >= w)
-				d = 1;
-			vep_parse_int(sp, p + l, d);
-		}
-	} else
-		vep_parse_int(sp, p, w);
-}
-
 /*---------------------------------------------------------------------
  */
 
diff --git a/bin/varnishd/cache_fetch.c b/bin/varnishd/cache_fetch.c
index b7f798f..a2a5ba0 100644
--- a/bin/varnishd/cache_fetch.c
+++ b/bin/varnishd/cache_fetch.c
@@ -85,7 +85,7 @@ vfp_nop_begin(struct sess *sp, size_t estimate)
  */
 
 static int __match_proto__()
-vfp_nop_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
+vfp_nop_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 {
 	ssize_t l, w;
 	struct storage *st;
@@ -314,10 +314,10 @@ fetch_eof(struct sess *sp, struct http_conn *htc)
 	assert(sp->wrk->body_status == BS_EOF);
 	sp->wrk->vfp->begin(sp, 0);
 	i = sp->wrk->vfp->bytes(sp, htc,
-#ifdef SIZE_T_MAX
-	    SIZE_T_MAX
+#ifdef SSIZE_T_MAX
+	    SSIZE_T_MAX
 #else
-	    sizeof(void*) == 4 ? ((size_t)1<<31) : ((size_t)1 << 63)
+	    sizeof(size_t) == 4 ? ((size_t)1<<30) : ((size_t)1 << 62)
 #endif
 	    ); 
 	if (i < 0) {
diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index be05a68..747a41a 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -340,7 +340,7 @@ vfp_gunzip_begin(struct sess *sp, size_t estimate)
 }
 
 static int __match_proto__()
-vfp_gunzip_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
+vfp_gunzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 {
 	struct vgz *vg;
 	ssize_t l, w;
@@ -408,7 +408,7 @@ vfp_gzip_begin(struct sess *sp, size_t estimate)
 }
 
 static int __match_proto__()
-vfp_gzip_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
+vfp_gzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
 {
 	struct vgz *vg;
 	ssize_t l, w;



More information about the varnish-commit mailing list