]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
decode_pair test point should take fr_dict_attr_t const *parent
authorAlan T. DeKok <aland@freeradius.org>
Sun, 19 Dec 2021 19:14:14 +0000 (14:14 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 21 Dec 2021 17:22:14 +0000 (12:22 -0500)
which lets us start decoding part way through the dictionary,
instead of always at the top

12 files changed:
src/bin/unit_test_attribute.c
src/lib/eap_aka_sim/base.h
src/lib/eap_aka_sim/decode.c
src/lib/io/pair.h
src/lib/tls/cache.c
src/lib/unlang/xlat_pair.c
src/protocols/dhcpv4/decode.c
src/protocols/dhcpv6/decode.c
src/protocols/dns/decode.c
src/protocols/internal/decode.c
src/protocols/internal/internal.h
src/protocols/radius/decode.c

index de3f168f1cf2b8e450ac8e048fe9d2c9bf9c5c95..aedd9b1935311c6ba3c6db67a835a58af39ade85 100644 (file)
@@ -1516,7 +1516,7 @@ static size_t command_decode_pair(command_result_t *result, command_file_ctx_t *
         *      point to produce fr_pair_ts.
         */
        while (to_dec < to_dec_end) {
-               slen = tp->func(cc->tmp_ctx, &head, cc->tmpl_rules.dict_def ? cc->tmpl_rules.dict_def : cc->config->dict,
+               slen = tp->func(cc->tmp_ctx, &head, fr_dict_root(cc->tmpl_rules.dict_def ? cc->tmpl_rules.dict_def : cc->config->dict),
                                (uint8_t *)to_dec, (to_dec_end - to_dec), decode_ctx);
                cc->last_ret = slen;
                if (slen <= 0) {
index b48c662804d57f21dce53eef00a140bfebf93ed5..1928c9b745fed23055f26d886157440cb020cd42 100644 (file)
@@ -253,7 +253,7 @@ extern size_t const fr_aka_sim_attr_sizes[FR_TYPE_MAX + 1][2];
 /*
  *     decode.c
  */
-ssize_t                fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict,
+ssize_t                fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent,
                                       uint8_t const *data, size_t data_len, void *decode_ctx);
 
 int            fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict,
index e8cb3acf174245fae8fe89ec227a4b4c1b056ad7..253e926314f0cbb57e2256a89594742ea587b5af 100644 (file)
@@ -910,7 +910,7 @@ static ssize_t sim_decode_pair_internal(TALLOC_CTX *ctx, fr_pair_list_t *out, fr
  *
  * @param[in] ctx              to allocate attributes in.
  * @param[in] out              where to insert the attributes.
- * @param[in] dict             for looking up attributes.
+ * @param[in] parent           for looking up attributes.
  * @param[in] data             data to parse.
  * @param[in] data_len         length of data.  For top level attributes packet_ctx must be the length
  *                             of the packet (so we can hunt for AT_IV), for Sub-TLVs it should
@@ -920,10 +920,10 @@ static ssize_t sim_decode_pair_internal(TALLOC_CTX *ctx, fr_pair_list_t *out, fr
  *     - The number of bytes parsed.
  *     - -1 on error.
  */
-ssize_t fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict,
-                          uint8_t const *data, size_t data_len, void *decode_ctx)
+ssize_t fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent,
+                              uint8_t const *data, size_t data_len, void *decode_ctx)
 {
-       return sim_decode_pair_internal(ctx, out, fr_dict_root(dict), data, data_len, decode_ctx);
+       return sim_decode_pair_internal(ctx, out, parent, data, data_len, decode_ctx);
 }
 
 /** Decode SIM/AKA/AKA' specific packet data
@@ -959,6 +959,7 @@ int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dic
        ssize_t                 ret;
        uint8_t const           *p = data;
        uint8_t const           *end = p + data_len;
+       fr_dict_attr_t const    *parent;
 
        /*
         *      We need at least enough data for the subtype
@@ -975,6 +976,7 @@ int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dic
                return -1;
        }
        p += 3;
+       parent = fr_dict_root(dict);
 
        /*
         *      Loop over all the attributes decoding
@@ -982,7 +984,7 @@ int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dic
         *      in the SIM/AKA/AKA' dict.
         */
        while (p < end) {
-               ret = fr_aka_sim_decode_pair(ctx, out, dict, p, end - p, decode_ctx);
+               ret = fr_aka_sim_decode_pair(ctx, out, parent, p, end - p, decode_ctx);
                if (ret <= 0) {
                        fr_strerror_const_push("Failed decoding AT");
                error:
@@ -1001,7 +1003,7 @@ int fr_aka_sim_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dic
        {
                fr_pair_t *vp;
 
-               vp = fr_pair_afrom_child_num(ctx, fr_dict_root(dict), FR_SUBTYPE);
+               vp = fr_pair_afrom_child_num(ctx, parent, FR_SUBTYPE);
                if (!vp) {
                        fr_strerror_const("Failed allocating subtype attribute");
                        goto error;
index f94ec72d1c30185a8d09be5f5a2649068f8af42f..a18696d37821481593a97b2aa3a80639eb7a1a4a 100644 (file)
@@ -124,15 +124,15 @@ typedef ssize_t (*fr_pair_encode_t)(fr_dbuff_t *out, fr_dcursor_t *cursor, void
  *
  * @param[in] ctx              to allocate new pairs in.
  * @param[in] out              to insert new pairs into.
- * @param[in] dict             to use to lookup attributes.
+ * @param[in] parent           to use for decoding
  * @param[in] data             to decode.
  * @param[in] data_len         The length of the incoming data.
- * @param[in] decode_ctx       Any decode specific data such as secrets or configurable.
+ * @param[in] decode_ctx       Any decode specific data such as secrets or temporary allocation contexts
  * @return
  *     - <= 0 on error.  May be the offset (as a negative value) where the error occurred.
  *     - > 0 on success.  How many bytes were decoded.
  */
-typedef ssize_t (*fr_pair_decode_t)(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict,
+typedef ssize_t (*fr_pair_decode_t)(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent,
                                    uint8_t const *data, size_t data_len, void *decode_ctx);
 
 int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out,
index cc55a33d33fb634fa25215d1803f80a2f13b7c94..53e89fa71768d67eac94d17b89b9986c4851cda6 100644 (file)
@@ -193,7 +193,7 @@ static int tls_cache_app_data_get(request_t *request, SSL_SESSION *sess)
         */
        while (fr_dbuff_remaining(&dbuff) > 0) {
                if (fr_internal_decode_pair_dbuff(request->session_state_ctx, &tmp,
-                                                 request->dict, &dbuff, NULL) < 0) {
+                                                 fr_dict_root(request->dict), &dbuff, NULL) < 0) {
                        fr_pair_list_free(&tmp);
                        RPEDEBUG("Failed decoding session-state");
                        return -1;
index e9fb2e0e3ed3f6126d5e1fbbe701ec72464aba5d..e61a8018b24f6814fd9e7437774222086b856caa 100644 (file)
@@ -30,7 +30,7 @@ RCSID("$Id$")
  *
  * @param[in] ctx              to allocate new pairs in.
  * @param[in] out              the cursor to update
- * @param[in] dict             to use to lookup attributes.
+ * @param[in] parent           to use as the root
  * @param[in] data             to decode.
  * @param[in] data_len         The length of the incoming data.
  * @param[in] decode_ctx       Any decode specific data such as secrets or configurable.
@@ -39,7 +39,7 @@ RCSID("$Id$")
  *     - <= 0 on error.  May be the offset (as a negative value) where the error occurred.
  *     - > 0 on success.  How many bytes were decoded.
  */
-static ssize_t fr_pair_decode_multi(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict,
+static ssize_t fr_pair_decode_multi(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent,
                                    uint8_t const *data, size_t data_len, void *decode_ctx, fr_pair_decode_t decode)
 {
        uint8_t const *p, *end;
@@ -58,7 +58,7 @@ static ssize_t fr_pair_decode_multi(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic
        while (p < end) {
                ssize_t len;
 
-               len = decode(ctx, &tmp, dict, p, end - p, decode_ctx);
+               len = decode(ctx, &tmp, parent, p, end - p, decode_ctx);
                if (len <= 0) {
                        fr_pair_list_free(&tmp);
                        return len - (p - data);
@@ -94,6 +94,7 @@ int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out,
        int             decoded = 0;
        fr_value_box_t  *vb = NULL;
        fr_pair_t       *vp = NULL;
+       fr_dict_attr_t const *parent = fr_dict_root(request->dict);
        fr_pair_list_t  head;
 
        fr_pair_list_init(&head);
@@ -109,7 +110,7 @@ int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out,
                        continue;
                }
 
-               len = fr_pair_decode_multi(ctx, &head, request->dict,
+               len = fr_pair_decode_multi(ctx, &head, parent,
                                           vb->vb_octets, vb->vb_length, decode_ctx, decode);
                if (len <= 0) {
                        fr_pair_list_free(&head);
@@ -119,7 +120,7 @@ int fr_pair_decode_value_box_list(TALLOC_CTX *ctx, fr_pair_list_t *out,
        }
 
        if (RDEBUG_ENABLED2) {
-               char const *name = fr_dict_root(request->dict)->name;
+               char const *name = parent->name;
 
                while ((vp = fr_pair_list_next(&head, vp))) {
                        RDEBUG2("decode %s: &%pP", name, vp);
index 69a19427737ea0bbcea80ecd12bc4b613de96a36..fbc494a48593bec81007e73aeacc35d2db1699dc 100644 (file)
@@ -592,10 +592,10 @@ static ssize_t fr_dhcpv4_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out,
        return data_len;
 }
 
-static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_t const *dict,
+static ssize_t decode_option(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_attr_t const *parent,
                                uint8_t const *data, size_t data_len, void *decode_ctx)
 {
-       fr_assert(dict == dict_dhcpv4);
+       fr_assert(parent == fr_dict_root(dict_dhcpv4));
 
        return fr_dhcpv4_decode_option(ctx, out, data, data_len, decode_ctx);
 }
index 4ac3f27971d1ab8c9d5a8fbfc9ec352076b4d381..5221b347efbd398f9059269c7af171d97a126a3e 100644 (file)
@@ -642,10 +642,10 @@ static ssize_t fr_dhcpv6_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out, uint
 }
 
 
-static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_t const *dict,
+static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_attr_t const *parent,
                           uint8_t const *data, size_t data_len, void *decode_ctx)
 {
-       fr_assert(dict == dict_dhcpv6);
+       fr_assert(parent == fr_dict_root(dict_dhcpv6));
 
        return decode_option(ctx, out, fr_dict_root(dict_dhcpv6), data, data_len, decode_ctx);
 }
index da5c8c9312f8c8aaaa20c5070fa5f298705fefe2..80b07a4d97dd35f4201b9775d1917372cf29c8fb 100644 (file)
@@ -582,13 +582,13 @@ ssize_t   fr_dns_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *packe
  *
  * @param[in] ctx context      to alloc new attributes in.
  * @param[in,out] out          Where to write the decoded options.
- * @param[in] dict             to lookup attributes in.
+ * @param[in] parent           to lookup attributes in.
  * @param[in] data             to parse.
  * @param[in] data_len         of data to parse.
  * @param[in] decode_ctx       Unused.
  */
-static ssize_t decode_rr(TALLOC_CTX *ctx, fr_pair_list_t *out,
-                        UNUSED fr_dict_t const *dict, uint8_t const *data, size_t data_len, void *decode_ctx)
+static ssize_t decode_rr(TALLOC_CTX *ctx, fr_pair_list_t *out, UNUSED fr_dict_attr_t const *parent,
+                        uint8_t const *data, size_t data_len, void *decode_ctx)
 {
        ssize_t                 slen;
        fr_dns_ctx_t    *packet_ctx = (fr_dns_ctx_t *) decode_ctx;
index 2e9153fc29bc709a6b01a8eb9c6b0614eb0cf8fc..19209054a50d51375cae77dd4f4c36b2cdd8bdba 100644 (file)
@@ -349,13 +349,13 @@ static ssize_t internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dic
 /** Create a single fr_pair_t and all its nesting
  *
  */
-ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_t const *dict,
+ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *list, fr_dict_attr_t const *parent,
                                uint8_t const *data, size_t data_len, void *decode_ctx)
 {
-       return fr_internal_decode_pair_dbuff(ctx, list, dict, &FR_DBUFF_TMP(data, data_len), decode_ctx);
+       return fr_internal_decode_pair_dbuff(ctx, list, parent, &FR_DBUFF_TMP(data, data_len), decode_ctx);
 }
 
-ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict,
+ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent,
                                fr_dbuff_t *dbuff, void *decode_ctx)
 {
        fr_pair_list_t  tmp;
@@ -364,7 +364,7 @@ ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_d
 
        fr_pair_list_init(&tmp);
 
-       slen = internal_decode_pair(ctx, &tmp, fr_dict_root(dict), &work_dbuff, decode_ctx);
+       slen = internal_decode_pair(ctx, &tmp, parent, &work_dbuff, decode_ctx);
        if (slen <= 0) {
                fr_pair_list_free(&tmp);
                return slen;
index 2d8e7e91960f1e65e2bcf872a9a1a9e19db4b451..5b940a67adb2a9166e48051079475948e2f3f4b7 100644 (file)
@@ -43,8 +43,8 @@
 
 ssize_t fr_internal_encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx);
 
-ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict,
+ssize_t fr_internal_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent,
                                uint8_t const *data, size_t data_len, void *decode_ctx);
 
-ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict,
+ssize_t fr_internal_decode_pair_dbuff(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent,
                                fr_dbuff_t *dbuff, void *decode_ctx);
index 103d09c172ef61be283cf09fa56b44d10c5d01a6..3aa260dc0adbc81d2d0b6c9d78f4385d13989fa5 100644 (file)
@@ -1878,10 +1878,10 @@ static ssize_t fr_radius_decode_proto(TALLOC_CTX *ctx, fr_pair_list_t *out,
                                test_ctx->secret, talloc_array_length(test_ctx->secret) - 1);
 }
 
-static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_t const *dict,
+static ssize_t decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, NDEBUG_UNUSED fr_dict_attr_t const *parent,
                           uint8_t const *data, size_t data_len, fr_radius_ctx_t *packet_ctx)
 {
-       fr_assert(dict == dict_radius);
+       fr_assert(parent == fr_dict_root(dict_radius));
 
        return fr_radius_decode_pair(ctx, out, data, data_len, packet_ctx);
 }