mediatek: add support for TOTOLINK A8000RU
[openwrt/staging/nbd.git] / package / utils / busybox / patches / 205-udhcpc_allow_zero_length_options.patch
1 From 7eed119b84b0f7efb7ef351940dd895dc2379eb3 Mon Sep 17 00:00:00 2001
2 From: Russell Senior <russell@personaltelco.net>
3 Date: Mon, 15 Mar 2021 23:27:58 -0700
4 Subject: [PATCH v2] udhcpc: ignore zero-length DHCP options
5
6 Discovered that the DHCP server on a TrendNet router (unknown model)
7 provides a zero-length option 12 (Host Name) in the DHCP ACK message. This
8 has the effect of causing udhcpc to drop the rest of the options, including
9 option 51 (IP Address Lease Time), 3 (Router), and 6 (Domain Name Server),
10 most importantly leaving the OpenWrt device with no default gateway.
11
12 The TrendNet behavior violates RFC 2132, which in Section 3.14 declares that
13 option 12 has a miniumum length of 1 octet. It is perhaps not a cosmic coincidence
14 that I found this behavior on Pi Day.
15
16 This patch allows zero length options without bailing out, by simply skipping them.
17
18 v2 changelog:
19 * advance the optionptr by two bytes, not one;
20 * add a message to warn about the rfc violation;
21
22 Signed-off-by: Russell Senior <russell@personaltelco.net>
23 ---
24 networking/udhcp/common.c | 9 +++++++--
25 1 file changed, 7 insertions(+), 2 deletions(-)
26
27 diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
28 index 4bc719001..a16fd85d0 100644
29 --- a/networking/udhcp/common.c
30 +++ b/networking/udhcp/common.c
31 @@ -277,8 +277,13 @@ uint8_t* FAST_FUNC udhcp_scan_options(struct dhcp_packet *packet, struct dhcp_sc
32 goto complain; /* complain and return NULL */
33 len = 2 + scan_state->optionptr[OPT_LEN];
34 scan_state->rem -= len;
35 - /* So far no valid option with length 0 known. */
36 - if (scan_state->rem < 0 || scan_state->optionptr[OPT_LEN] == 0)
37 + /* skip any options with zero length */
38 + if (scan_state->optionptr[OPT_LEN] == 0) {
39 + scan_state->optionptr += 2;
40 + bb_simple_error_msg("warning: zero length DHCP option violates rfc2132, skipping");
41 + continue;
42 + }
43 + if (scan_state->rem < 0)
44 goto complain; /* complain and return NULL */
45
46 if (scan_state->optionptr[OPT_CODE] == DHCP_OPTION_OVERLOAD) {
47 --
48 2.30.1
49