dhcpd: Wait until next whole second bug reintroduced with #10 - ping-timeout-ms configuration option
name: dhcpd ping-timeout-ms 999 waits until next whole second
about: tv_usec can overflow in do_ping_check() and is later capped to 999999 in add_timeout()
https://gitlab.isc.org/isc-projects/dhcp/-/blob/master/server/dhcp.c#L3708
tv.tv_usec
may be assigned value up to 1999998
https://gitlab.isc.org/isc-projects/dhcp/-/blob/master/common/dispatch.c#L286
tv_usec
is here capped to 999999
instead of adding to tv_sec
.
To Reproduce Steps to reproduce the behavior:
- set dhcpd configuration value
ping-timeout-ms
to999
- send
DHCPDISCOVER
just before second ends - The server waits until whole second (miliseconds==000) instead waiting exactly 999 miliseconds
Expected behavior The server waits requested miliseconds for icmp echo reply.
Environment: Bug was discovered in current source code (31e68e5e, master as of writing this bugreport) as I was searching for similar bug in version 4.1.1 (which was fixed later, before introduction of ping-timeout-ms configuration option)
Additional Information I did not actually tested the errorneous behaviour of current version.
Describe the solution you'd like
Divide tv_usec
by 1000000
and add result into tv_sec
and keep only remainder.
(I have no opinion about to which of the two functions should be the fix applied to.)