]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add packet decode test point for DHCPv4
authorAlan T. DeKok <aland@freeradius.org>
Wed, 30 Oct 2019 17:51:35 +0000 (13:51 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 30 Oct 2019 17:51:35 +0000 (13:51 -0400)
src/bin/.gitignore
src/bin/all.mk
src/protocols/dhcpv4/decode.c

index c9c40d67e334ec0a63aae1e5e01b7df47f6b7d0f..eeda1988b5e30a4024ab7a7ea38d205a1a4a3e24 100644 (file)
@@ -2,4 +2,5 @@ checkrad
 radlast
 radtest
 fuzzer_radius.mk
+fuzzer_dhcpv4.mk
 fuzzer_dhcpv6.mk
index a24b3c4576a28a8c5081a7dfff19e63b5b9dae1c..9a0a0034889b040d3ea892209f8f8af9ce1b93f9 100644 (file)
@@ -34,7 +34,7 @@ endef
 #  have a test point for packet decoding.  See
 #  src/protocols/radius/decode.c for an example.
 #
-PROTOCOLS = radius dhcpv6
+PROTOCOLS = radius dhcpv4 dhcpv6
 
 $(foreach X,${PROTOCOLS},$(eval $(call FUZZ_PROTOCOL,${X})))
 endif
index 39247a81e8c012309d51d977767f12017bfb9b58..54f3c6f391ff46bc1dc3d74c37b7d3e14470624b 100644 (file)
@@ -445,6 +445,26 @@ static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
        return 0;
 }
 
+
+static ssize_t fr_dhcpv4_decode_proto(UNUSED void *proto_ctx, uint8_t const *data, size_t data_len)
+{
+       ssize_t rcode;
+//     fr_dhcpv4_ctx_t *test_ctx = talloc_get_type_abort(proto_ctx, fr_dhcpv4_ctx_t);
+       RADIUS_PACKET *packet;
+
+       if (!fr_dhcpv4_ok(data, data_len, NULL, NULL)) return -1;
+
+       packet = fr_dhcpv4_packet_alloc(data, data_len);
+       if (!packet) return -1;
+
+       memcpy(&packet->data, &data, sizeof(packet->data)); /* const issues */
+       packet->data_len = data_len;
+       rcode = fr_dhcpv4_packet_decode(packet);
+       talloc_free(packet);
+
+       return rcode;
+}
+
 /*
  *     Test points
  */
@@ -453,3 +473,9 @@ fr_test_point_pair_decode_t dhcpv4_tp_decode_pair = {
        .test_ctx       = decode_test_ctx,
        .func           = fr_dhcpv4_decode_option
 };
+
+extern fr_test_point_proto_decode_t dhcpv4_tp_decode_proto;
+fr_test_point_proto_decode_t dhcpv4_tp_decode_proto = {
+       .test_ctx       = decode_test_ctx,
+       .func           = fr_dhcpv4_decode_proto
+};