Commit 7fd3aa3f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Don't let the form of the argument to hash_data() leak into the

production of the hash-key.

Fixes	#1296
parent 80b3ecc0
......@@ -155,20 +155,15 @@ HSH_DeleteObjHead(struct dstat *ds, struct objhead *oh)
}
void
HSH_AddString(struct req *req, const char *str)
HSH_AddString(const struct req *req, const char *str)
{
int l;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
if (str == NULL)
str = "";
l = strlen(str);
AN(req->sha256ctx);
SHA256_Update(req->sha256ctx, str, l);
SHA256_Update(req->sha256ctx, "#", 1);
VSLb(req->vsl, SLT_Hash, "%s", str);
if (str != NULL)
SHA256_Update(req->sha256ctx, str, strlen(str));
else
SHA256_Update(req->sha256ctx, &str, sizeof str);
}
/*---------------------------------------------------------------------
......
......@@ -257,7 +257,7 @@ VRT_handling(const struct vrt_ctx *ctx, unsigned hand)
}
/*--------------------------------------------------------------------
* Add an element to the array/list of hash bits.
* Feed data into the hash calculation
*/
void
......@@ -275,7 +275,13 @@ VRT_hashdata(const struct vrt_ctx *ctx, const char *str, ...)
if (p == vrt_magic_string_end)
break;
HSH_AddString(ctx->req, p);
VSLb(ctx->vsl, SLT_Hash, "%s", str);
}
/*
* Add a 'field-separator' to make it more difficult to
* manipulate the hash.
*/
HSH_AddString(ctx->req, NULL);
}
/*--------------------------------------------------------------------*/
......
......@@ -69,7 +69,7 @@ enum lookup_e HSH_Lookup(struct req *, struct objcore **, struct objcore **,
void HSH_Ref(struct objcore *o);
void HSH_Drop(struct worker *, struct object **);
void HSH_Init(const struct hash_slinger *slinger);
void HSH_AddString(struct req *, const char *str);
void HSH_AddString(const struct req *, const char *str);
void HSH_Insert(struct worker *, const void *hash, struct objcore *);
void HSH_Purge(struct req *, struct objhead *, double ttl, double grace);
void HSH_config(const char *h_arg);
......
varnishtest "hash key depends on argument form to hash_data()"
server s1 {
rxreq
txresp -hdr "OK: yes"
rxreq
txresp -hdr "OK: no"
} -start
varnish v1 -vcl+backend {
sub vcl_hash {
if (req.http.foo == "1") {
hash_data("123");
} else {
hash_data("1" + req.http.foo + "3");
}
return (hash);
}
} -start
client c1 {
txreq -hdr "foo: 1"
rxresp
expect resp.http.ok == "yes"
txreq -hdr "foo: 2"
rxresp
expect resp.http.ok == "yes"
} -run
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment