[4.0] 2852b2d Skip NULL and empty arguments when hashing. Hash all other arguments.

Lasse Karstensen lkarsten at varnish-software.com
Mon Sep 22 16:38:23 CEST 2014


commit 2852b2d729ef0122ea6f08af2350f49ff49848f1
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 b0c10aa..090039f 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