Skip to content

Commit

Permalink
[retry] Fix potential use-after-free in timer_expired()
Browse files Browse the repository at this point in the history
timer->refcnt is allowed to be NULL, in which case the timer's
expired() method may end up freeing the timer object.

Discovered using valgrind.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Jul 16, 2011
1 parent 5b41381 commit 17f09df
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/net/retry.c
Expand Up @@ -148,6 +148,7 @@ void stop_timer ( struct retry_timer *timer ) {
* @v timer Retry timer
*/
static void timer_expired ( struct retry_timer *timer ) {
struct refcnt *refcnt = timer->refcnt;
int fail;

/* Stop timer without performing RTT calculations */
Expand All @@ -169,8 +170,9 @@ static void timer_expired ( struct retry_timer *timer ) {

/* Call expiry callback */
timer->expired ( timer, fail );
/* If refcnt is NULL, then timer may already have been freed */

ref_put ( timer->refcnt );
ref_put ( refcnt );
}

/**
Expand Down

0 comments on commit 17f09df

Please sign in to comment.