]> git.ipfire.org Git - thirdparty/openvpn.git/commit
Avoid overflow in wakeup time computation
authorSelva Nair <selva.nair@gmail.com>
Tue, 6 Mar 2018 06:09:28 +0000 (01:09 -0500)
committerGert Doering <gert@greenie.muc.de>
Sat, 24 Mar 2018 16:32:17 +0000 (17:32 +0100)
commitf158c0e1df13ae1b697cdc7f189ddd1575a0c1aa
tree4e896a8f7869f9ee529cf86ed9071d5754471252
parent68b97b25e4c479156d697bf3df90a4b68fbbbcea
Avoid overflow in wakeup time computation

Time interval arithmetic can overflow especially when user
defined intervals are involved. E.g., see Trac #922.

Avoid this by reordering the arithmetic operation in
event_timeout_trigger(). Also avoid unnecessary casting of time
variable to int.

Time until wakeup is now calculated like:

time_t wakeup = (last - now) + delay

Here delay is of type int, but is +ve by construction. Time backtrack
protection in OpenVPN ensures (last - now) <= 0. Then the above
expression cannot overflow (provided time_t is at least as large
as int).

A similar expression in interval.h is also changed.

(This patch grew out of patch 168 by Steffan Karger.)

Trac: #922

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Message-Id: <1520316568-8983-1-git-send-email-selva.nair@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg16634.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/interval.c
src/openvpn/interval.h