aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)
1465 if (packet.d6_msg_type == D6_MSG_REPLY) { 1465 if (packet.d6_msg_type == D6_MSG_REPLY) {
1466 uint32_t lease_seconds; 1466 uint32_t lease_seconds;
1467 struct d6_option *option; 1467 struct d6_option *option;
1468 int address_timeout; 1468 unsigned address_timeout;
1469 int prefix_timeout; 1469 unsigned prefix_timeout;
1470 type_is_ok: 1470 type_is_ok:
1471 address_timeout = 0; 1471 address_timeout = 0;
1472 prefix_timeout = 0; 1472 prefix_timeout = 0;
@@ -1626,12 +1626,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1626 move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4); 1626 move_from_unaligned32(lease_seconds, iaaddr->data + 16 + 4);
1627 lease_seconds = ntohl(lease_seconds); 1627 lease_seconds = ntohl(lease_seconds);
1628/// TODO: check for 0 lease time? 1628/// TODO: check for 0 lease time?
1629 /* paranoia: must not be prone to overflows */
1630 if (lease_seconds > 0x7fffffff / 1000)
1631 lease_seconds = 0x7fffffff / 1000;
1632 address_timeout = lease_seconds / 2;
1633 bb_error_msg("%s obtained, lease time %u", 1629 bb_error_msg("%s obtained, lease time %u",
1634 "IPv6", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); 1630 "IPv6", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
1631 address_timeout = lease_seconds;
1635 } 1632 }
1636 if (option_mask32 & OPT_d) { 1633 if (option_mask32 & OPT_d) {
1637 struct d6_option *iaprefix; 1634 struct d6_option *iaprefix;
@@ -1662,18 +1659,16 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
1662 } 1659 }
1663 move_from_unaligned32(lease_seconds, iaprefix->data + 4); 1660 move_from_unaligned32(lease_seconds, iaprefix->data + 4);
1664 lease_seconds = ntohl(lease_seconds); 1661 lease_seconds = ntohl(lease_seconds);
1665 /* paranoia: must not be prone to overflows */
1666 if (lease_seconds > 0x7fffffff / 1000)
1667 lease_seconds = 0x7fffffff / 1000;
1668 prefix_timeout = lease_seconds / 2;
1669 bb_error_msg("%s obtained, lease time %u", 1662 bb_error_msg("%s obtained, lease time %u",
1670 "prefix", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds); 1663 "prefix", /*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
1664 prefix_timeout = lease_seconds;
1671 } 1665 }
1672 if (!address_timeout) 1666 if (!address_timeout)
1673 address_timeout = prefix_timeout; 1667 address_timeout = prefix_timeout;
1674 if (!prefix_timeout) 1668 if (!prefix_timeout)
1675 prefix_timeout = address_timeout; 1669 prefix_timeout = address_timeout;
1676 timeout = address_timeout > prefix_timeout ? prefix_timeout : address_timeout; 1670 /* note: "int timeout" will not overflow even with 0xffffffff inputs here: */
1671 timeout = (prefix_timeout < address_timeout ? prefix_timeout : address_timeout) / 2;
1677 /* paranoia: must not be too small */ 1672 /* paranoia: must not be too small */
1678 if (timeout < 0x10) 1673 if (timeout < 0x10)
1679 timeout = 0x10; 1674 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)
1732 /* paranoia: must not be too small and not prone to overflows */ 1732 /* paranoia: must not be too small and not prone to overflows */
1733 if (lease_seconds < 0x10) 1733 if (lease_seconds < 0x10)
1734 lease_seconds = 0x10; 1734 lease_seconds = 0x10;
1735 if (lease_seconds > 0x7fffffff / 1000) 1735 //if (lease_seconds > 0x7fffffff)
1736 lease_seconds = 0x7fffffff / 1000; 1736 // lease_seconds = 0x7fffffff;
1737 //^^^not necessary since "timeout = lease_seconds / 2"
1738 //does not overflow even for 0xffffffff.
1737 } 1739 }
1738#if ENABLE_FEATURE_UDHCPC_ARPING 1740#if ENABLE_FEATURE_UDHCPC_ARPING
1739 if (opt & OPT_a) { 1741 if (opt & OPT_a) {