From: Alan T. DeKok Date: Mon, 5 Oct 2020 17:06:06 +0000 (-0400) Subject: add tests. and decode multiple VSAs in option 125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3448dc8d52f78aa0bb6a3bc4c417ce4e5c46d16c;p=thirdparty%2Ffreeradius-server.git add tests. and decode multiple VSAs in option 125 --- diff --git a/src/protocols/dhcpv4/decode.c b/src/protocols/dhcpv4/decode.c index 9960582fc8e..dd496777cce 100644 --- a/src/protocols/dhcpv4/decode.c +++ b/src/protocols/dhcpv4/decode.c @@ -359,6 +359,7 @@ static ssize_t decode_vsa(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_attr_t c ssize_t len; uint32_t pen; fr_dict_attr_t const *da; + uint8_t const *end; FR_PROTO_HEX_DUMP(data, data_len, "decode_vsa"); @@ -377,6 +378,9 @@ static ssize_t decode_vsa(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_attr_t c return decode_value(ctx, cursor, parent, data, data_len); } + end = data + data_len; + +next: memcpy(&pen, data, sizeof(pen)); pen = htonl(pen); @@ -408,6 +412,9 @@ static ssize_t decode_vsa(TALLOC_CTX *ctx, fr_cursor_t *cursor, fr_dict_attr_t c len = decode_tlv(ctx, cursor, da, data + 5, data[4]); if (len <= 0) return len; + data += 5 + len; + if (data < end) goto next; + /* * Tell the caller we read all of it, even if we didn't. */ diff --git a/src/tests/unit/protocols/dhcpv4/vendor.txt b/src/tests/unit/protocols/dhcpv4/vendor.txt new file mode 100644 index 00000000000..b0c31ae9073 --- /dev/null +++ b/src/tests/unit/protocols/dhcpv4/vendor.txt @@ -0,0 +1,17 @@ +# +# Test vectors for Vendor-Specific DHCP attributes +# +proto dhcpv4 +proto-dictionary dhcpv4 + +encode-pair Cisco-Indirect-Image-Filename = "aa.txt" +match 7d 0d 00 00 00 09 08 05 06 61 61 2e 74 78 74 + +decode-pair - +match Cisco-Indirect-Image-Filename = "aa.txt" + +decode-pair 7d 1a 00 00 00 09 08 05 06 61 61 2e 74 78 74 00 00 00 09 08 05 06 62 62 2e 74 78 74 +match Cisco-Indirect-Image-Filename = "aa.txt", Cisco-Indirect-Image-Filename = "bb.txt" + +count +match 8