]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
decode malformed TLVs as raw.
authorAlan T. DeKok <aland@freeradius.org>
Wed, 16 Dec 2020 16:31:50 +0000 (11:31 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 16 Dec 2020 16:31:50 +0000 (11:31 -0500)
And add tests

src/protocols/dhcpv4/decode.c
src/tests/unit/protocols/dhcpv4/error.txt

index 85f254f5d0152718c4d277128b6c8f7beb56d495..9bb6a9bc0fa75f42568c81b7b44b3cfbe904e8c9 100644 (file)
@@ -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);
index 430fc8f066969532ed1447c0e550b0d1e56c4c7a..1812a83552eed4348ea5d260946ac6046c373b5a 100644 (file)
@@ -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