Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Oct 2012 17:35:09 +0200
From:      Erik Cederstrand <erik@cederstrand.dk>
To:        FreeBSD Hackers <hackers@FreeBSD.org>
Subject:   time_t when used as timedelta
Message-ID:  <787F09EF-E3F7-467E-B023-B7846509D2A1@cederstrand.dk>

next in thread | raw e-mail | index | archive | help

Hi list,

I'm looking at this possible divide-by zero in dhclient: http://scan.freebsd.your.org/freebsd-head/WORLD/2012-10-07-amd64/report-nBhqE2.html.gz#EndPath

In this specific case, it's obvious from the intention of the code that ip->client->interval is always >0, but it's not obvious to me in the code. I could add an assert before the possible divide-by-zero:

assert(ip->client->interval > 0);

But looking at the code, I'm not sure it's very elegant. ip->client->interval is defined as time_t (see src/sbin/dhclient/dhcpd.h), which is a signed integer type, if I'm correct. However, some time_t members of struct client_state and struct client_config (see said header file) are assumed in the code to be positive and possibly non-null. Instead of plastering the code with asserts, is there something like an utime_t type? Or are there better ways to enforce the invariant?

Thanks,
Erik


Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?787F09EF-E3F7-467E-B023-B7846509D2A1>