[master] b0d96f6 Skip NULL and empty arguments when hashing. Hash all other arguments.

Nils Goroll nils.goroll at uplex.de
Mon Aug 18 12:32:42 CEST 2014


commit b0d96f6a6049904f702dcae3238d3e00af23ae62
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Aug 18 12:32:19 2014 +0200

    Skip NULL and empty arguments when hashing. Hash all other 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

diff --git a/bin/varnishtest/tests/v00026.vtc b/bin/varnishtest/tests/v00026.vtc
index e1b77b9..711861d 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,15 @@ varnish v1 -vcl+backend {
 		return(pass);
 	}
 	sub vcl_backend_fetch {
-		set bereq.backend = h1.backend(bereq.url);
+		if (bereq.url == "/nohdr") {
+		   	set bereq.backend = h1.backend(bereq.http.Void);
+		} else if (bereq.url == "/emptystring") {
+			set bereq.backend = h1.backend("");
+		} else if (bereq.url == "/13") {
+			set bereq.backend = h1.backend(bereq.http.Void + "" + bereq.url);
+		} else {
+			set bereq.backend = h1.backend(bereq.url);
+		}
 	}
 
 } -start
@@ -51,5 +63,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..afef7ed 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 && *p != '\0')
+			SHA256_Update(&sha_ctx, p, strlen(p));
 		p = va_arg(ap, const char *);
 	}
 	va_end(ap);



More information about the varnish-commit mailing list