From: Alan T. DeKok Date: Wed, 30 Oct 2019 17:51:35 +0000 (-0400) Subject: add packet decode test point for DHCPv4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0797f0fed6d070bf3214e317d2ac7b159e7efaaa;p=thirdparty%2Ffreeradius-server.git add packet decode test point for DHCPv4 --- diff --git a/src/bin/.gitignore b/src/bin/.gitignore index c9c40d67e33..eeda1988b5e 100644 --- a/src/bin/.gitignore +++ b/src/bin/.gitignore @@ -2,4 +2,5 @@ checkrad radlast radtest fuzzer_radius.mk +fuzzer_dhcpv4.mk fuzzer_dhcpv6.mk diff --git a/src/bin/all.mk b/src/bin/all.mk index a24b3c4576a..9a0a0034889 100644 --- a/src/bin/all.mk +++ b/src/bin/all.mk @@ -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 diff --git a/src/protocols/dhcpv4/decode.c b/src/protocols/dhcpv4/decode.c index 39247a81e8c..54f3c6f391f 100644 --- a/src/protocols/dhcpv4/decode.c +++ b/src/protocols/dhcpv4/decode.c @@ -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 +};