]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
add fr_dict_t* to test_ctx parameters
authorAlan T. DeKok <aland@freeradius.org>
Mon, 2 Dec 2024 19:11:39 +0000 (14:11 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 2 Dec 2024 19:41:52 +0000 (14:41 -0500)
which lets CBOR / DER know what protocol they're using

24 files changed:
src/bin/fuzzer.c
src/bin/unit_test_attribute.c
src/lib/eap_aka_sim/decode.c
src/lib/eap_aka_sim/encode.c
src/lib/io/test_point.h
src/lib/unlang/xlat_builtin.c
src/lib/util/fuzzer.c
src/protocols/arp/base.c
src/protocols/bfd/decode.c
src/protocols/bfd/encode.c
src/protocols/cbor/base.c
src/protocols/dhcpv4/decode.c
src/protocols/dhcpv4/encode.c
src/protocols/dhcpv6/decode.c
src/protocols/dhcpv6/encode.c
src/protocols/dns/decode.c
src/protocols/dns/encode.c
src/protocols/radius/decode.c
src/protocols/radius/encode.c
src/protocols/tacacs/decode.c
src/protocols/tacacs/encode.c
src/protocols/tftp/decode.c
src/protocols/tftp/encode.c
src/protocols/vmps/vmps.c

index 0baa119684f866010d15ae1a0c487a5d6f263c2f..3ca17f9601735631324c5429fbf6cd7bd7193a6e 100644 (file)
@@ -251,7 +251,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len)
        fr_pair_list_init(&vps);
        if (!init) LLVMFuzzerInitialize(NULL, NULL);
 
-       if (tp->test_ctx && (tp->test_ctx(&decode_ctx, NULL) < 0)) {
+       if (tp->test_ctx && (tp->test_ctx(&decode_ctx, NULL, dict) < 0)) {
                fr_perror("fuzzer: Failed initializing test point decode_ctx");
                fr_exit_now(EXIT_FAILURE);
        }
index fc277cff965464d4907475169694f931c5683d08..ab94fe563e671f0924dc4a1efedc2ab5fb01ab45 100644 (file)
@@ -1571,7 +1571,7 @@ static size_t command_decode_pair(command_result_t *result, command_file_ctx_t *
        p += slen;
        fr_skip_whitespace(p);
 
-       if (tp->test_ctx && (tp->test_ctx(&decode_ctx, cc->tmp_ctx) < 0)) {
+       if (tp->test_ctx && (tp->test_ctx(&decode_ctx, cc->tmp_ctx, dictionary_current(cc)) < 0)) {
                fr_strerror_const_push("Failed initialising decoder testpoint");
                RETURN_COMMAND_ERROR();
        }
@@ -1672,7 +1672,7 @@ static size_t command_decode_proto(command_result_t *result, command_file_ctx_t
        p += slen;
        fr_skip_whitespace(p);
 
-       if (tp->test_ctx && (tp->test_ctx(&decode_ctx, cc->tmp_ctx) < 0)) {
+       if (tp->test_ctx && (tp->test_ctx(&decode_ctx, cc->tmp_ctx, dictionary_current(cc)) < 0)) {
                fr_strerror_const_push("Failed initialising decoder testpoint");
                RETURN_COMMAND_ERROR();
        }
@@ -1906,7 +1906,7 @@ static size_t command_encode_pair(command_result_t *result, command_file_ctx_t *
                fr_skip_whitespace(p);
        }
 
-       if (tp->test_ctx && (tp->test_ctx(&encode_ctx, cc->tmp_ctx) < 0)) {
+       if (tp->test_ctx && (tp->test_ctx(&encode_ctx, cc->tmp_ctx, dictionary_current(cc)) < 0)) {
                fr_strerror_const_push("Failed initialising encoder testpoint");
                CLEAR_TEST_POINT(cc);
                RETURN_COMMAND_ERROR();
@@ -2125,7 +2125,7 @@ static size_t command_encode_proto(command_result_t *result, command_file_ctx_t
 
        p += ((size_t)slen);
        fr_skip_whitespace(p);
-       if (tp->test_ctx && (tp->test_ctx(&encode_ctx, cc->tmp_ctx) < 0)) {
+       if (tp->test_ctx && (tp->test_ctx(&encode_ctx, cc->tmp_ctx, dictionary_current(cc)) < 0)) {
                fr_strerror_const_push("Failed initialising encoder testpoint");
                CLEAR_TEST_POINT(cc);
                RETURN_COMMAND_ERROR();
index c541101a204e44b6e1bf0822377f42fbaa340ed2..2b18253a25906232dab9609c3b4a897bf5b37d4b 100644 (file)
@@ -1023,7 +1023,7 @@ static fr_aka_sim_ctx_t *test_ctx_init(TALLOC_CTX *ctx, uint8_t const *k_encr, s
 /*
  *     Test ctx data
  */
-static int decode_test_ctx_sim(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx_sim(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_aka_sim_ctx_t        *test_ctx;
        static uint8_t          k_encr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
@@ -1040,7 +1040,7 @@ static int decode_test_ctx_sim(void **out, TALLOC_CTX *ctx)
 }
 
 
-static int decode_test_ctx_aka(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx_aka(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_aka_sim_ctx_t *test_ctx;
        static uint8_t          k_encr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
@@ -1056,7 +1056,7 @@ static int decode_test_ctx_aka(void **out, TALLOC_CTX *ctx)
        return 0;
 }
 
-static int decode_test_ctx_sim_rfc4186(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx_sim_rfc4186(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_aka_sim_ctx_t *test_ctx;
        static uint8_t          k_encr[] = { 0x53, 0x6e, 0x5e, 0xbc, 0x44 ,0x65, 0x58, 0x2a,
index 55052ebf40fb0c5f0924da07938a6be91758618d..c7e48ba2abf9bc666adb02fdad2bccd37e304b5e 100644 (file)
@@ -1015,7 +1015,7 @@ static fr_aka_sim_ctx_t *test_ctx_init(TALLOC_CTX *ctx, uint8_t const *k_encr, s
 /*
  *     Test ctx data
  */
-static int encode_test_ctx_sim(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx_sim(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_aka_sim_ctx_t        *test_ctx;
        static uint8_t          k_encr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
@@ -1031,7 +1031,7 @@ static int encode_test_ctx_sim(void **out, TALLOC_CTX *ctx)
        return 0;
 }
 
-static int encode_test_ctx_aka(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx_aka(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_aka_sim_ctx_t        *test_ctx;
        static uint8_t          k_encr[] = { 0x00, 0x01, 0x02, 0x03, 0x04 ,0x05, 0x06, 0x07,
@@ -1047,7 +1047,7 @@ static int encode_test_ctx_aka(void **out, TALLOC_CTX *ctx)
        return 0;
 }
 
-static int encode_test_ctx_sim_rfc4186(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx_sim_rfc4186(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_aka_sim_ctx_t        *test_ctx;
        static uint8_t          k_encr[] = { 0x53, 0x6e, 0x5e, 0xbc, 0x44 ,0x65, 0x58, 0x2a,
index 1f2c691123902839083a89b17a21aeb4a42d2f1c..7587a6048c5d2536d3f4ba2401db40ee793c849d 100644 (file)
@@ -43,9 +43,10 @@ typedef enum {
  *
  * @param[out] out     Where the decoder context should be written.
  * @param[in] ctx      to allocate the test point context in.
+ * @param[in] dict     the default dictionary context for the test point
  * @return proto or pair encoder or decoder ctx.
  */
-typedef int (*fr_test_point_ctx_alloc_t)(void **out, TALLOC_CTX *ctx);
+typedef int (*fr_test_point_ctx_alloc_t)(void **out, TALLOC_CTX *ctx, fr_dict_t const *dict);
 
 /** A generic interface for decoding packets to fr_pair_ts
  *
index 2a0dea1259c2d2c2557986d0f7ecd9e827d65396..9755e088c02f2b93e2725ba01911d796054ee161 100644 (file)
@@ -3764,7 +3764,7 @@ static xlat_action_t protocol_decode_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
        fr_test_point_pair_decode_t const       *tp_decode = *(void * const *)xctx->inst;
 
        if (tp_decode->test_ctx) {
-               if (tp_decode->test_ctx(&decode_ctx, ctx) < 0) {
+               if (tp_decode->test_ctx(&decode_ctx, ctx, request->dict) < 0) {
                        return XLAT_ACTION_FAIL;
                }
        }
@@ -3899,7 +3899,7 @@ static xlat_action_t protocol_encode_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
         *      Create the encoding context.
         */
        if (tp_encode->test_ctx) {
-               if (tp_encode->test_ctx(&encode_ctx, vpt) < 0) {
+               if (tp_encode->test_ctx(&encode_ctx, vpt, request->dict) < 0) {
                        talloc_free(vpt);
                        return XLAT_ACTION_FAIL;
                }
index b167686ed70de6ac47c803e00989ebb1e6a57646..864f2e54299e1b7db03d32a26fbf8173626d8688 100644 (file)
@@ -24,7 +24,7 @@ RCSID("$Id$")
 
 #include <freeradius-devel/io/test_point.h>
 
-static int decode_test_ctx(void **out, UNUSED TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, UNUSED TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        *out = NULL;
        return 0;
index 5deb6d5ea176b2ea4257e4e3bf71e0d0cb887f0a..f3b58faa30befebf3f9fbb5d56834cfd6c9c07ab 100644 (file)
@@ -305,7 +305,7 @@ typedef struct {
        bool            tmp;
 } fr_arp_ctx_t;
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_arp_ctx_t *test_ctx;
 
index debfba70d724937aadc27efb3cee01d330223bfc..e2788a0ea0e406ca83e33f273b8480f5d6d64dd6 100644 (file)
@@ -99,7 +99,7 @@ ssize_t fr_bfd_decode(TALLOC_CTX *ctx, fr_pair_list_t *out,
        return slen;
 }
 
-static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_bfd_ctx_t    *test_ctx;
 
index 6c8153134cf5e2601198614054bf338b729e2a93..232a68bda8f65fd8723d00117bc0c2cdbb8cf6ec 100644 (file)
@@ -162,7 +162,7 @@ ssize_t fr_bfd_encode(uint8_t *out, size_t outlen, UNUSED uint8_t const *origina
 }
 
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_bfd_ctx_t    *test_ctx;
 
index 3d39ae5fd68299920b40b198b847ee3fcac70a56..7d55f2306d21222eb23745720968769cf6c8294a 100644 (file)
@@ -69,3 +69,39 @@ extern fr_test_point_pair_decode_t cbor_tp_decode_pair;
 fr_test_point_pair_decode_t cbor_tp_decode_pair = {
        .func           = decode_pair
 };
+
+static int decode_test_ctx(void **out, UNUSED TALLOC_CTX *ctx, fr_dict_t const *dict)
+{
+       *out = UNCONST(fr_dict_t *, dict);
+
+       return 0;
+}
+
+static ssize_t encode_proto(UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vps, uint8_t *data, size_t data_len, UNUSED void *proto_ctx)
+{
+       fr_dbuff_t dbuff;
+       fr_dcursor_t cursor;
+
+       FR_DBUFF_INIT(&dbuff, data, data_len);
+
+       fr_pair_dcursor_init(&cursor, vps);
+       return encode_pair(&dbuff, &cursor, NULL);
+}
+
+static ssize_t decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *data, size_t data_len, void *proto_ctx)
+{
+       fr_dict_t *dict = proto_ctx;
+
+       return decode_pair(ctx, out, fr_dict_root(dict), data, data_len, proto_ctx);
+}
+
+extern fr_test_point_proto_encode_t cbor_tp_encode_proto;
+fr_test_point_proto_encode_t cbor_tp_encode_proto = {
+       .func           = encode_proto
+};
+
+extern fr_test_point_proto_decode_t cbor_tp_decode_proto;
+fr_test_point_proto_decode_t cbor_tp_decode_proto = {
+       .test_ctx       = decode_test_ctx,
+       .func           = decode_proto
+};
index 297cb6eed164111e0a67012cbd7f196f04015253..2b1da445986e08f1de2618b250c4f15aa3ba2cb4 100644 (file)
@@ -685,7 +685,7 @@ ssize_t     fr_dhcpv4_decode_foreign(TALLOC_CTX *ctx, fr_pair_list_t *out,
 }
 
 
-static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_dhcpv4_ctx_t *test_ctx;
 
index 804aa699298e3636eb78960daa48967705ff1408..8df8f68d6751ca2d2d73413b08b06ee8be8e3268 100644 (file)
@@ -803,7 +803,7 @@ static ssize_t fr_dhcpv4_encode_proto(UNUSED TALLOC_CTX *ctx, fr_pair_list_t *vp
        return fr_dhcpv4_encode_dbuff(&FR_DBUFF_TMP(data, data_len), NULL, 0, 0, vps);
 }
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_dhcpv4_ctx_t *test_ctx;
 
index c33c13905743cf91838d25153f9429fb7908e23b..034b2c8e043162b0c310e2ae661907f1259e8d79 100644 (file)
@@ -472,7 +472,7 @@ ssize_t     fr_dhcpv6_decode_foreign(TALLOC_CTX *ctx, fr_pair_list_t *out,
        return data_len;
 }
 
-static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_dhcpv6_decode_ctx_t  *test_ctx;
 
index c78dd365d22d6a42b65ac26c007fe230372df3dc..84989eb5d2a83a0288dc95762277fe80ea73bcdb 100644 (file)
@@ -740,7 +740,7 @@ ssize_t     fr_dhcpv6_encode_foreign(fr_dbuff_t *dbuff, fr_pair_list_t const *list)
 }
 
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_dhcpv6_encode_ctx_t  *test_ctx;
 
index 7dd755c80d3768415600b7565f9b82092690e1fa..d237a297b9036bf56777e165200f58bea9ba0112 100644 (file)
@@ -372,7 +372,7 @@ static ssize_t decode_rr(TALLOC_CTX *ctx, fr_pair_list_t *out, UNUSED fr_dict_at
 /*
  *     Test points
  */
-static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_dns_ctx_t *test_ctx;
 
index 3acb03c834f7aa463a8b65296c1ddcbf65728f9e..eab30c4c1cfad29dc024fb283809123fb1a915ce 100644 (file)
@@ -509,7 +509,7 @@ ssize_t fr_dns_encode(fr_dbuff_t *dbuff, fr_pair_list_t *vps, fr_dns_ctx_t *pack
        return fr_dbuff_set(dbuff, &work_dbuff);
 }
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_dns_ctx_t    *test_ctx;
 
index b908d894a38b7a85679e4989648296fb18990e13..d3a35d64965c71d0596b57859fe1b0ddbc1dc166 100644 (file)
@@ -2138,7 +2138,7 @@ static int _test_ctx_free(fr_radius_decode_ctx_t *ctx)
        return 0;
 }
 
-static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        static uint8_t vector[RADIUS_AUTH_VECTOR_LENGTH] = {
                0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
index 2a64d54fcb0eb1468941defce6eb7dab8839e2a9..9656d434fa75250d9dd150cb800389c62cb23b47 100644 (file)
@@ -1699,7 +1699,7 @@ ssize_t   fr_radius_encode_foreign(fr_dbuff_t *dbuff, fr_pair_list_t const *list)
 }
 
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        static uint8_t vector[RADIUS_AUTH_VECTOR_LENGTH] = {
                0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
index 88374eb01c42ba9911fdb8c5ff1b2bf1276509df..ad7d42c97101c6e922b5fe9ce18b9715bb870742 100644 (file)
@@ -1088,7 +1088,7 @@ static int _encode_test_ctx(fr_tacacs_ctx_t *proto_ctx)
        return 0;
 }
 
-static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_tacacs_ctx_t *test_ctx;
 
index 378aad317972e85d009df2d23fe56c181caf9f9d..b601b19bd593f201a1ce7d12418b33b0b8541174 100644 (file)
@@ -1057,7 +1057,7 @@ static int _encode_test_ctx(fr_tacacs_ctx_t *proto_ctx)
        return 0;
 }
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_tacacs_ctx_t *test_ctx;
 
index 106a0161b95d8eda0f0ec116748046c932ff947e..23a8e9734a3cae9418e16f02985468f4f7798612 100644 (file)
@@ -292,7 +292,7 @@ static int _decode_test_ctx(UNUSED fr_tftp_ctx_t *proto_ctx)
        return 0;
 }
 
-static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_tftp_ctx_t *test_ctx;
 
index 3ade5916865e76eedd14e69087b1fd0885d1d486..97f162e8cee472a6774beaf7ba0b337e2e5bca73 100644 (file)
@@ -254,7 +254,7 @@ static int _encode_test_ctx(UNUSED fr_tftp_ctx_t *proto_ctx)
        return 0;
 }
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_tftp_ctx_t *test_ctx;
 
index 5942c3c9a9e54fe66b7ccdfc95ad2e992be0a5e4..137ce952f0a67ac2cf61160d71d7106d8604d396 100644 (file)
@@ -521,7 +521,7 @@ static int _decode_test_ctx(UNUSED fr_vmps_ctx_t *proto_ctx)
        return 0;
 }
 
-static int decode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int decode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_vmps_ctx_t *test_ctx;
 
@@ -562,7 +562,7 @@ static int _encode_test_ctx(UNUSED fr_vmps_ctx_t *proto_ctx)
        return 0;
 }
 
-static int encode_test_ctx(void **out, TALLOC_CTX *ctx)
+static int encode_test_ctx(void **out, TALLOC_CTX *ctx, UNUSED fr_dict_t const *dict)
 {
        fr_vmps_ctx_t *test_ctx;