Commit 344a709c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

std.fileread() should not blindly return whatever file it returned

last without checking if the filename changed.

Fixes		#1145
Testcase by:	tobixen
parent ecb8b097
varnishtest "Test fileread for std VMOD"
shell {
printf "File One" > "${tmpdir}/one"
printf "File Two" > "${tmpdir}/two"
printf "File Three" > "${tmpdir}/three"
}
server s1 {
loop 3 {
rxreq
txresp
}
} -start
varnish v1 -vcl+backend {
import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
sub vcl_deliver {
set resp.http.foo = std.fileread("${tmpdir}" + req.url);
}
} -start
client c1 {
txreq -url "/one"
rxresp
expect resp.http.foo == "File One"
txreq -url "/two"
rxresp
expect resp.http.foo == "File Two"
txreq -url "/three"
rxresp
expect resp.http.foo == "File Three"
} -run
client c1 -run
client c1 -run
......@@ -85,17 +85,21 @@ free_frfile(void *ptr)
const char *
vmod_fileread(struct sess *sp, struct vmod_priv *priv, const char *file_name)
{
struct frfile *frf;
struct frfile *frf = NULL;
char *s;
(void)sp;
AN(priv);
if (priv->priv != NULL) {
CAST_OBJ_NOTNULL(frf, priv->priv, CACHED_FILE_MAGIC);
return (frf->contents);
if (!strcmp(file_name, frf->file_name))
return (frf->contents);
}
AZ(pthread_mutex_lock(&frmtx));
if (frf != NULL)
frf->refcount--;
VTAILQ_FOREACH(frf, &frlist, list) {
if (!strcmp(file_name, frf->file_name)) {
frf->refcount++;
......
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