-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

When multiple arguments were passed to vmod_hash_backend, only the
first argument was re-used for the number of arguments passed.

Fixes #1568


Re phk on irc: I don't see how we should handle NULL differntly from "". If no
bytes are processed, the hash does not change.

Nils

- -- 

** * * UPLEX - Nils Goroll Systemoptimierung

Scheffelstraße 32
22301 Hamburg

tel +49 40 28805731
mob +49 170 2723133
fax +49 40 42949753

xmpp://[email protected]/

http://uplex.de/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iEYEARECAAYFAlPpPjYACgkQYhlPtokm/hv19gCfXpqBNwfB2QxNIW+OrWqHENEk
B9cAoJzKjz2G2pTErNDMnUMvyI0brGUl
=9zp+
-----END PGP SIGNATURE-----
From fbb0891ca5648b0da787a67ce1836fd38cf96777 Mon Sep 17 00:00:00 2001
From: Nils Goroll <[email protected]>
Date: Tue, 12 Aug 2014 00:00:03 +0200
Subject: [PATCH] Skip NULL arguments when hashing. Hash all arguments.

When multiple arguments were passed to vmod_hash_backend, only the
first argument was re-used for the number of arguments passed.

Fixes #1568
---
 bin/varnishtest/tests/v00026.vtc | 20 +++++++++++++++++++-
 lib/libvmod_directors/hash.c     |  3 ++-
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/bin/varnishtest/tests/v00026.vtc b/bin/varnishtest/tests/v00026.vtc
index e1b77b9..a541528 100644
--- a/bin/varnishtest/tests/v00026.vtc
+++ b/bin/varnishtest/tests/v00026.vtc
@@ -12,6 +12,10 @@ server s2 {
 	txresp -hdr "Foo: 2" -body "2"
 	rxreq
 	txresp -hdr "Foo: 4" -body "4"
+	rxreq
+	txresp -hdr "Foo: 6" -body "6"
+	rxreq
+	txresp -hdr "Foo: 8" -body "8"
 } -start
 
 
@@ -28,7 +32,13 @@ varnish v1 -vcl+backend {
 		return(pass);
 	}
 	sub vcl_backend_fetch {
-		set bereq.backend = h1.backend(bereq.url);
+		if (bereq.url == "/emptystring") {
+			set bereq.backend = h1.backend("");
+		} else if (bereq.url == "/nohdr") {
+			set bereq.backend = h1.backend(bereq.http.Void);
+		} else {
+			set bereq.backend = h1.backend(bereq.url);
+		}
 	}
 
 } -start
@@ -51,5 +61,13 @@ client c1 {
 	rxresp
 	expect resp.http.foo == "4"
 
+	txreq -url /emptystring
+	rxresp
+	expect resp.http.foo == "6"
+
+	txreq -url /nohdr
+	rxresp
+	expect resp.http.foo == "8"
+
 
 } -run
diff --git a/lib/libvmod_directors/hash.c b/lib/libvmod_directors/hash.c
index 35c8ed7..767f9e6 100644
--- a/lib/libvmod_directors/hash.c
+++ b/lib/libvmod_directors/hash.c
@@ -110,7 +110,8 @@ vmod_hash_backend(const struct vrt_ctx *ctx, struct vmod_directors_hash *rr,
 	va_start(ap, arg);
 	p = arg;
 	while (p != vrt_magic_string_end) {
-		SHA256_Update(&sha_ctx, arg, strlen(arg));
+		if (p != NULL)
+			SHA256_Update(&sha_ctx, p, strlen(p));
 		p = va_arg(ap, const char *);
 	}
 	va_end(ap);
-- 
2.0.1

Attachment: 0001-Skip-NULL-arguments-when-hashing.-Hash-all-arguments.patch.sig
Description: PGP signature

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to