Commit d1c3c75a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

A long time ago, I wrote fetch_straight() in fact it was one of the

very first functions ever written in Varnish.   Since I knew
that the file stevedore would always return the size you asked for,
or panic, I didn't bother to actually check how big the storage
segment he allocated was, I just knew it would be the right size.

Guess what, segments are finite size in the -spersistent stevedore
so you may in fact _not_ get what you ask for.

(Cue music: Theme Music from The Keystone Kops)

DuH!


git-svn-id: http://www.varnish-cache.org/svn/trunk@4202 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e27a4f8e
......@@ -53,7 +53,7 @@ fetch_straight(struct sess *sp, struct http_conn *htc, const char *b)
int i;
unsigned char *p;
uintmax_t cll;
unsigned cl;
unsigned cl, sl;
struct storage *st;
cll = strtoumax(b, NULL, 0);
......@@ -63,18 +63,24 @@ fetch_straight(struct sess *sp, struct http_conn *htc, const char *b)
cl = (unsigned)cll;
assert((uintmax_t)cl == cll); /* Protect against bogusly large values */
st = STV_alloc(sp, cl);
VTAILQ_INSERT_TAIL(&sp->obj->store, st, list);
st->len = cl;
sp->obj->len = cl;
p = st->ptr;
while (cl > 0) {
i = HTC_Read(htc, p, cl);
if (i <= 0)
return (-1);
p += i;
cl -= i;
st = STV_alloc(sp, cl);
VTAILQ_INSERT_TAIL(&sp->obj->store, st, list);
sl = st->space;
if (sl > cl)
sl = cl;
p = st->ptr;
while (sl > 0) {
i = HTC_Read(htc, p, sl);
if (i <= 0)
return (-1);
p += i;
st->len += i;
sp->obj->len += i;
sl -= i;
cl -= i;
}
}
return (0);
}
......
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