[git commit] dhcpd: fix an improper widening conversion

Denys Vlasenko vda.linux at googlemail.com
Tue Jan 27 20:59:40 UTC 2015


commit: http://git.busybox.net/busybox/commit/?id=936c401077cc68d9e3dd7f1b0b293ee03ce02bf5
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

We wanted to detect when tv_sec = unsigned1 - unsigned2
underflows by looking at tv_sec's sign. But if tv_sec
is long and it is wider than unsigned, we get unsigned -> long
conversion which is in this case never negative.

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 networking/udhcp/dhcpd.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 4b3ed24..2de074f 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -413,7 +413,8 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
 
 		max_sock = udhcp_sp_fd_set(&rfds, server_socket);
 		if (server_config.auto_time) {
-			tv.tv_sec = timeout_end - monotonic_sec();
+			/* cast to signed is essential if tv_sec is wider than int */
+			tv.tv_sec = (int)(timeout_end - monotonic_sec());
 			tv.tv_usec = 0;
 		}
 		retval = 0;


More information about the busybox-cvs mailing list