summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2009-01-08 16:47:01 -0800
committerBen Pfaff <blp@nicira.com>2009-01-12 17:17:15 -0800
commit9092532ddc84a4006d49b81db8be5ccc66b59181 (patch)
tree24f5c9d9ac19b2c78c95ca337256bc01b460ce85
parente4d1978d6bae679654c9aabc08dac28343951614 (diff)
downloadopenvswitch-9092532ddc84a4006d49b81db8be5ccc66b59181.tar.gz
dhcp-client: Don't report long time to expiration after lease expires.
There is a race between time advancing past the lease expiration time and actually transitioning to the expired state. Fix this race. Found by Chris Eagle via Fortify.
-rw-r--r--lib/dhcp-client.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/dhcp-client.c b/lib/dhcp-client.c
index 460fedf90..7704c8a54 100644
--- a/lib/dhcp-client.c
+++ b/lib/dhcp-client.c
@@ -356,7 +356,12 @@ dhclient_get_state_elapsed(const struct dhclient *cli)
unsigned int
dhclient_get_lease_remaining(const struct dhclient *cli)
{
- return dhclient_is_bound(cli) ? cli->lease_expiration - time_now() : 0;
+ if (dhclient_is_bound(cli)) {
+ time_t now = time_now();
+ return cli->lease_expiration > now ? cli->lease_expiration - now : 0;
+ } else {
+ return 0;
+ }
}
/* If 'cli' is bound to an IP address, returns that IP address; otherwise,