Skip to content

Commit

Permalink
Take sizeof pool_task into account when reserving WS in SES_Wait
Browse files Browse the repository at this point in the history
The assert on WS_ReserveSize() in ses_handle() can not trip because
sizeof (struct pool_task) is less than sizeof (struct waited). But to safe
guard against future problems if that were to change, this patch makes
sure that the session workspace can hold the largest of them before
entering the waiter, erroring out if not.
  • Loading branch information
mbgrydeland committed Feb 4, 2020
1 parent 618e9f9 commit 2d8fc1a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions bin/varnishd/cache/cache_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
wp->magic = 0;
wp = NULL;

/* The WS was reserved in SES_Wait() */
WS_Release(sp->ws, 0);

switch (ev) {
Expand All @@ -431,6 +432,7 @@ ses_handle(struct waited *wp, enum wait_event ev, vtim_real now)
case WAITER_ACTION:
pp = sp->pool;
CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
/* SES_Wait() guarantees the next will not assert. */
assert(sizeof *tp <= WS_ReserveSize(sp->ws, sizeof *tp));
tp = (void*)sp->ws->f;
tp->func = xp->unwait;
Expand All @@ -454,6 +456,7 @@ SES_Wait(struct sess *sp, const struct transport *xp)
{
struct pool *pp;
struct waited *wp;
unsigned u;

CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(xp, TRANSPORT_MAGIC);
Expand All @@ -467,10 +470,15 @@ SES_Wait(struct sess *sp, const struct transport *xp)
VTCP_nonblocking(sp->fd);

/*
* put struct waited on the workspace
* Put struct waited on the workspace. Make sure that the
* workspace can hold enough space for the largest of struct
* waited and pool_task, as pool_task will be needed when coming
* off the waiter again.
*/
if (WS_ReserveSize(sp->ws, sizeof(struct waited))
< sizeof(struct waited)) {
u = sizeof (struct waited);
if (sizeof (struct pool_task) > u)
u = sizeof (struct pool_task);
if (!WS_ReserveSize(sp->ws, u)) {
SES_Delete(sp, SC_OVERLOAD, NAN);
return;
}
Expand Down

0 comments on commit 2d8fc1a

Please sign in to comment.