summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-01-17 13:55:51 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-01-17 13:55:51 +0100
commit7c44b600f9b2ca545421cb88147275e1351ba81f (patch)
tree3fb1daf3b354c71d834c81d9b0a2a9aba301db95
parent64211ce6fa9222de0c6f52c50ff7caf1bfbd301e (diff)
udhcpc[6]: remove overzealous timeout clamping code
function old new delta udhcpc_main 2840 2826 -14 udhcpc6_main 2699 2670 -29 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/udhcp/d6_dhcpc.c17
-rw-r--r--networking/udhcp/dhcpc.c6
2 files changed, 10 insertions, 13 deletions
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c
index 460f3d9a4..f3a7b827c 100644
--- a/networking/udhcp/d6_dhcpc.c
+++ b/networking/udhcp/d6_dhcpc.c
@@ -1465,8 +1465,8 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
if (packet.d6_msg_type == D6_MSG_REPLY) {
uint32_t lease_seconds;
struct d6_option *option;
- int address_timeout;
- int prefix_timeout;
+ unsigned address_timeout;
+ unsigned prefix_timeout;
type_is_ok:
address_timeout = 0;
prefix_timeout = 0;
@@ -1626,12 +1626,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4);
lease_seconds = ntohl(lease_seconds);
/// TODO: check for 0 lease time?
- /* paranoia: must not be prone to overflows */
- if (lease_seconds > 0x7fffffff / 1000)
- lease_seconds = 0x7fffffff / 1000;
- address_timeout = lease_seconds / 2;
bb_error_msg("%s obtained, lease time %u",
"IPv6", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
+ address_timeout = lease_seconds;
}
if (option_mask32 & OPT_d) {
struct d6_option *iaprefix;
@@ -1662,18 +1659,16 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
}
move_from_unaligned32(lease_seconds, iaprefix->data + 4);
lease_seconds = ntohl(lease_seconds);
- /* paranoia: must not be prone to overflows */
- if (lease_seconds > 0x7fffffff / 1000)
- lease_seconds = 0x7fffffff / 1000;
- prefix_timeout = lease_seconds / 2;
bb_error_msg("%s obtained, lease time %u",
"prefix", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
+ prefix_timeout = lease_seconds;
}
if (!address_timeout)
address_timeout = prefix_timeout;
if (!prefix_timeout)
prefix_timeout = address_timeout;
- timeout = address_timeout > prefix_timeout ? prefix_timeout : address_timeout;
+ /* note: "int timeout" will not overflow even with 0xffffffff inputs here: */
+ timeout = (prefix_timeout < address_timeout ? prefix_timeout : address_timeout) / 2;
/* paranoia: must not be too small */
if (timeout < 0x10)
timeout = 0x10;
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 55f21c187..385fc4998 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -1732,8 +1732,10 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
/* paranoia: must not be too small and not prone to overflows */
if (lease_seconds < 0x10)
lease_seconds = 0x10;
- if (lease_seconds > 0x7fffffff / 1000)
- lease_seconds = 0x7fffffff / 1000;
+ //if (lease_seconds > 0x7fffffff)
+ // lease_seconds = 0x7fffffff;
+ //^^^not necessary since "timeout = lease_seconds / 2"
+ //does not overflow even for 0xffffffff.
}
#if ENABLE_FEATURE_UDHCPC_ARPING
if (opt & OPT_a) {