From: Alan T. DeKok Date: Wed, 16 Dec 2020 16:31:50 +0000 (-0500) Subject: decode malformed TLVs as raw. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84030d38378979c1cee650c242fa842a924eca65;p=thirdparty%2Ffreeradius-server.git decode malformed TLVs as raw. And add tests --- diff --git a/src/protocols/dhcpv4/decode.c b/src/protocols/dhcpv4/decode.c index 85f254f5d01..9bb6a9bc0fa 100644 --- a/src/protocols/dhcpv4/decode.c +++ b/src/protocols/dhcpv4/decode.c @@ -262,7 +262,18 @@ static ssize_t decode_tlv(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_attr_t c uint8_t const *end = data + data_len; fr_dict_attr_t const *child; - if (data_len < 3) return -1; /* type, length, value */ + /* + * Type, length, data. If that doesn't exist, we decode + * the data as "raw" in the parents context/ + */ + if (data_len < 3) { + fr_pair_t *vp; + + vp = fr_raw_from_network(ctx, parent, data, data_len); + if (!vp) return -1; + fr_cursor_append(cursor, vp); + return data_len; + } FR_PROTO_TRACE("%s called to parse %zu byte(s)", __FUNCTION__, data_len); FR_PROTO_HEX_DUMP(data, data_len, NULL); diff --git a/src/tests/unit/protocols/dhcpv4/error.txt b/src/tests/unit/protocols/dhcpv4/error.txt index 430fc8f0669..1812a83552e 100644 --- a/src/tests/unit/protocols/dhcpv4/error.txt +++ b/src/tests/unit/protocols/dhcpv4/error.txt @@ -19,5 +19,26 @@ match raw.Subnet-Selection-Option = 0x010203 decode-proto 0101 0600 f59e ad14 0000 0000 0b0c 0c0c 0000 0000 0000 0000 0a0b 0b0b 4eaa 0000 0010 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 6382 5363 3501 0176 0931 302e 322e 3130 2e30 3d04 6a69 6d61 ff00 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 match Opcode = Client-Message, Hardware-Type = Ethernet, Hardware-Address-Length = 6, Hop-Count = 0, Transaction-Id = 4120816916, Number-of-Seconds = 0, Flags = 0, Client-IP-Address = 11.12.12.12, Your-IP-Address = 0.0.0.0, Server-IP-Address = 0.0.0.0, Gateway-IP-Address = 10.11.11.11, Client-Hardware-Address = 4e:aa:00:00:00:10, Message-Type = Discover, raw.Subnet-Selection-Option = 0x31302e322e31302e30, Client-Identifier = 0x6a696d61, Network-Subnet = 10.11.11.11/32 +# +# decode TLV which doesn't contain enough data to be a TLV. +# +decode-pair 52 02 01 02 +match raw.Relay-Agent-Information = 0x0102 + +encode-pair - +match 52 02 01 02 + +# +# This is correct +# +encode-pair Router-Address = 127.0.0.1, Router-Address = 127.0.0.2 +match 03 08 7f 00 00 01 7f 00 00 02 + +# +# But if we don't have enough data, the whole thing is corrupt. +# +decode-pair 03 07 7f 00 00 01 7f 00 00 +match raw.Router-Address = 0x7f0000017f0000 + count -match 12 +match 20