]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Unwrap fr_value_box_from_network
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 21 Sep 2021 13:02:32 +0000 (08:02 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 21 Sep 2021 13:02:52 +0000 (08:02 -0500)
14 files changed:
src/lib/util/struct.c
src/lib/util/value.c
src/lib/util/value.h
src/modules/rlm_eap/types/rlm_eap_fast/eap_fast.c
src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c
src/modules/rlm_unbound/rlm_unbound.c
src/modules/rlm_unpack/rlm_unpack.c
src/protocols/dhcpv4/decode.c
src/protocols/dhcpv4/packet.c
src/protocols/dhcpv6/base.c
src/protocols/dhcpv6/decode.c
src/protocols/internal/decode.c
src/protocols/radius/decode.c
src/protocols/vmps/vmps.c

index 046ba9bfdd9ce40237d3016633e365feef537b2b..ff7f8ccbb98e84d9eec1c6b0f65f437a841c6725 100644 (file)
@@ -48,7 +48,8 @@ fr_pair_t *fr_raw_from_network(TALLOC_CTX *ctx, fr_dict_attr_t const *parent, ui
        fr_dict_unknown_free(&child);
        if (!vp) return NULL;
 
-       if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da, data, data_len, true) < 0) {
+       if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                     &FR_DBUFF_TMP(data, data_len), data_len, true) < 0) {
                talloc_free(vp);
                return NULL;
        }
@@ -255,7 +256,8 @@ ssize_t fr_struct_from_network(TALLOC_CTX *ctx, fr_dcursor_t *cursor,
                 *      If we can't decode this field, then the entire
                 *      structure is treated as a raw blob.
                 */
-               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da, p, child_length, true) < 0) {
+               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                             &FR_DBUFF_TMP(p, child_length), child_length, true) < 0) {
                        FR_PROTO_TRACE("fr_struct_from_network - failed decoding child VP");
                        talloc_free(vp);
                unknown:
@@ -613,7 +615,7 @@ ssize_t fr_struct_to_network(fr_dbuff_t *dbuff,
                                fr_dict_attr_t **u;
 
                                memcpy(&u, &c, sizeof(c)); /* const issues */
-                               memcpy(u, &vp->da, sizeof(vp->da));                     
+                               memcpy(u, &vp->da, sizeof(vp->da));
                        }
 
                        /*
index 5f2923d298627d862df71db05e768b59c8008fd6..54829abf85a288a0a31007b509bed645c37a7487 100644 (file)
@@ -1538,7 +1538,7 @@ ssize_t fr_value_box_to_network(fr_dbuff_t *dbuff, fr_value_box_t const *value)
  * @param[out] dst     value_box to write the result to.
  * @param[in] type     to decode data to.
  * @param[in] enumv    Aliases for values.
- * @param[in] src      Binary data to decode.
+ * @param[in] dbuff    Binary data to decode.
  * @param[in] len      Length of data to decode.  For fixed length types we only
  *                     decode complete values.
  * @param[in] tainted  Whether the value came from a trusted source.
@@ -1549,16 +1549,8 @@ ssize_t fr_value_box_to_network(fr_dbuff_t *dbuff, fr_value_box_t const *value)
  */
 ssize_t fr_value_box_from_network(TALLOC_CTX *ctx,
                                  fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv,
-                                 uint8_t const *src, size_t len,
+                                 fr_dbuff_t *dbuff, size_t len,
                                  bool tainted)
-{
-       return fr_value_box_from_network_dbuff(ctx, dst, type, enumv, &FR_DBUFF_TMP(src, len), len, tainted);
-}
-
-ssize_t fr_value_box_from_network_dbuff(TALLOC_CTX *ctx,
-                                       fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv,
-                                       fr_dbuff_t *dbuff, size_t len,
-                                       bool tainted)
 {
        size_t          min, max;
        fr_dbuff_t      work_dbuff = FR_DBUFF(dbuff);
index 6aa7e5d23a226882a777a7374fa1c74a3e9299ad..ae4dbd098daa501f069b3a59f7b1bf418043a0b3 100644 (file)
@@ -667,12 +667,10 @@ int               fr_value_box_to_key(uint8_t **out, size_t *outlen, fr_value_box_t const *va
 /** Special value to ensure other encoding/decoding errors don't overlap
  */
 #define FR_VALUE_BOX_NET_MAX   (FR_VALUE_BOX_NET_OOM + 1)
+
 ssize_t                fr_value_box_from_network(TALLOC_CTX *ctx,
                                          fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv,
-                                         uint8_t const *src, size_t len, bool tainted);
-ssize_t                fr_value_box_from_network_dbuff(TALLOC_CTX *ctx,
-                                               fr_value_box_t *dst, fr_type_t type, fr_dict_attr_t const *enumv,
-                                               fr_dbuff_t *dbuff, size_t len, bool tainted);
+                                         fr_dbuff_t *dbuff, size_t len, bool tainted);
 
 int            fr_value_box_cast(TALLOC_CTX *ctx, fr_value_box_t *dst,
                                  fr_type_t dst_type, fr_dict_attr_t const *dst_enumv,
@@ -812,7 +810,7 @@ int         fr_value_box_list_concat_in_place(TALLOC_CTX *ctx,
                                                  size_t max_size);
 
 char           *fr_value_box_list_aprint(TALLOC_CTX *ctx, fr_value_box_list_t const *list, char const *delim,
-                                        fr_sbuff_escape_rules_t const *e_rules);
+                                         fr_sbuff_escape_rules_t const *e_rules);
 
 int            fr_value_box_list_acopy(TALLOC_CTX *ctx, fr_value_box_list_t *out, fr_value_box_list_t const *in);
 
index 3b7421b435ebfecb355298bd0c87176a58fa6f8e..f1999512856c5a9cd6a3dbc8c103d6910e37f2f3 100644 (file)
@@ -457,7 +457,8 @@ ssize_t eap_fast_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_
                        MEM(vp = fr_pair_afrom_da(ctx, da));
                }
 
-               ret = fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da, p, len, true);
+               ret = fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da,
+                                               &FR_DBUFF_TMP(p, (size_t)len), len, true);
                if (ret != len) {
                        fr_pair_to_unknown(vp);
                        fr_pair_value_memdup(vp, p, len, true);
index e7590cdbb06b2bfe6192b52f4550be97e4f1e81e..9262d9ea272579e8e8f17a9301e27239ef002bcb 100644 (file)
@@ -239,7 +239,8 @@ static ssize_t eap_ttls_decode_pair(request_t *request, TALLOC_CTX *ctx, fr_dcur
                }
 
 do_value:
-               ret = fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da, p, value_len, true);
+               ret = fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                               &FR_DBUFF_TMP(p, (size_t)value_len), value_len, true);
                if (ret < 0) {
                        /*
                         *      Mandatory bit is set, and the attribute
index 48d2bd4213a2d99d81677fadf7e2bfd4d9b997fd..889b6650fe821372f7b53bbf9b2b9ca2ad526c2a 100644 (file)
@@ -203,7 +203,7 @@ static void xlat_unbound_callback(void *mydata, int rcode, void *packet, int pac
                case FR_TYPE_IPV6_ADDR:
                case FR_TYPE_OCTETS:
                        if (fr_value_box_from_network(ur->out_ctx, vb, ur->return_type, NULL,
-                                                     (uint8_t *)fr_dbuff_current(&dbuff), rdlength, true) < 0) {
+                                                     &dbuff, rdlength, true) < 0) {
                        error:
                                talloc_free(vb);
                                fr_dlist_talloc_free(&ur->list);
@@ -226,7 +226,7 @@ static void xlat_unbound_callback(void *mydata, int rcode, void *packet, int pac
                                }
                                priority_vb = fr_value_box_alloc_null(ur->out_ctx);
                                if (fr_value_box_from_network(ur->out_ctx, priority_vb, FR_TYPE_UINT16, NULL,
-                                                             (uint8_t *)fr_dbuff_current(&dbuff), 2, true) < 0) {
+                                                             &dbuff, 2, true) < 0) {
                                        talloc_free(priority_vb);
                                        goto error;
                                }
index fe65a32a3e4706a8ac5ee0ed35de90171f35fe42..89a554eb4d6c0fb5328c779bfd5587dcbe5f7de4 100644 (file)
@@ -129,7 +129,9 @@ static xlat_action_t unpack_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, request_t *
         *      Call the generic routines to get data from the
         *      "network" buffer.
         */
-       if (fr_value_box_from_network(ctx, vb, type, NULL, input + offset, input_len - offset, data_vb->tainted) < 0) {
+       if (fr_value_box_from_network(ctx, vb, type, NULL,
+                                     &FR_DBUFF_TMP(input + offset, input_len - offset),
+                                     input_len - offset, data_vb->tainted) < 0) {
                RPEDEBUG("Failed decoding %s", type_vb->vb_strvalue);
                talloc_free(vb);
                return XLAT_ACTION_FAIL;
index f8a9ababc99e5d800273ad9f2977d75b1997b6d0..2c36b947190ba2b3a357b0f6c9166332c2deef5a 100644 (file)
@@ -178,7 +178,8 @@ static ssize_t decode_value_internal(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_d
        {
                ssize_t ret;
 
-               ret = fr_value_box_from_network(vp, &vp->data, vp->da->type, da, p, end - p, true);
+               ret = fr_value_box_from_network(vp, &vp->data, vp->da->type, da,
+                                               &FR_DBUFF_TMP(p, end - p), end - p, true);
                if (ret < 0) {
                raw:
                        FR_PROTO_TRACE("decoding as unknown type");
index b110a72e71d08063cf5c10b8df37949cecf295f8..a6642608125c968b5daba2797f8656adbdc10d3e 100644 (file)
@@ -185,7 +185,8 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
 
                default:
                        if (fr_value_box_from_network(vp, &vp->data, vp->vp_type, vp->da,
-                                                     p, dhcp_header_sizes[i], true) < 0) goto error;
+                                                     &FR_DBUFF_TMP(p, (size_t)dhcp_header_sizes[i]),
+                                                     dhcp_header_sizes[i], true) < 0) goto error;
                        break;
                }
                p += dhcp_header_sizes[i];
@@ -351,14 +352,16 @@ int fr_dhcpv4_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_d
                /*
                 *      Gateway address is set - use that one
                 */
-               fr_value_box_from_network(vp, &box, FR_TYPE_IPV4_ADDR, NULL, data + 24, 4, true);
+               fr_value_box_from_network(vp, &box, FR_TYPE_IPV4_ADDR, NULL,
+                                         &FR_DBUFF_TMP(data + 24, 4), 4, true);
                fr_value_box_cast(vp, &vp->data, vp->da->type, vp->da, &box);
 
        } else {
                /*
                 *      else, store client address whatever it is
                 */
-               fr_value_box_from_network(vp, &box, FR_TYPE_IPV4_ADDR, NULL, data + 12, 4, true);
+               fr_value_box_from_network(vp, &box, FR_TYPE_IPV4_ADDR, NULL,
+                                         &FR_DBUFF_TMP(data + 12, 4), 4, true);
                fr_value_box_cast(vp, &vp->data, vp->da->type, vp->da, &box);
        }
 
index 03f0a8971acef1b76259f8c57f89d9f423a3f4ef..3588887a32107b273239733c58fe3a6007cecbc1 100644 (file)
@@ -680,21 +680,24 @@ ssize_t   fr_dhcpv6_decode(TALLOC_CTX *ctx, uint8_t const *packet, size_t packet_l
                 */
                vp = fr_pair_afrom_da(ctx, attr_hop_count);
                if (!vp) goto fail;
-               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, NULL, packet + 1, 1, true) < 0) {
+               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, NULL,
+                                             &FR_DBUFF_TMP(packet + 1, 1), 1, true) < 0) {
                        goto fail;
                }
                fr_dcursor_append(cursor, vp);
 
                vp = fr_pair_afrom_da(ctx, attr_relay_link_address);
                if (!vp) goto fail;
-               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, NULL, packet + 2, 16, true) < 0) {
+               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, NULL,
+                                             &FR_DBUFF_TMP(packet + 2, 16), 16, true) < 0) {
                        goto fail;
                }
                fr_dcursor_append(cursor, vp);
 
                vp = fr_pair_afrom_da(ctx, attr_relay_peer_address);
                if (!vp) goto fail;
-               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, NULL, packet + 2 + 16, 16, true) < 0) {
+               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, NULL,
+                                             &FR_DBUFF_TMP(packet + 2 + 16, 16), 16, true) < 0) {
                        goto fail;
                }
 
index c95af9ce4814b42421285691af20e27b478e582c..cee8772081814bf392f7fb5ee45f614cf554707e 100644 (file)
@@ -85,7 +85,8 @@ static ssize_t decode_raw(TALLOC_CTX *ctx, fr_dcursor_t *cursor, UNUSED fr_dict_
        vp = fr_pair_afrom_da(ctx, unknown);
        if (!vp) return PAIR_DECODE_OOM;
 
-       slen = fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da, data, data_len, true);
+       slen = fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                        &FR_DBUFF_TMP(data, data_len), data_len, true);
        if (slen < 0) {
                talloc_free(vp);
                da = unknown;
@@ -223,7 +224,8 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_dict_t con
                vp = fr_pair_afrom_da(ctx, parent);
                if (!vp) return PAIR_DECODE_OOM;
 
-               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da, data, data_len, true) < 0) {
+               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                             &FR_DBUFF_TMP(data, data_len), data_len, true) < 0) {
                        talloc_free(vp);
                        goto raw;
                }
@@ -267,7 +269,8 @@ static ssize_t decode_value(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_dict_t con
                vp = fr_pair_afrom_da(ctx, parent);
                if (!vp) return PAIR_DECODE_OOM;
 
-               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da, data, data_len, true) < 0) {
+               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                             &FR_DBUFF_TMP(data, data_len), data_len, true) < 0) {
                        talloc_free(vp);
                        goto raw;
                }
index 1ac2cda8da4d03ce536b4d51f3120d28a7f377c9..ab1c1ba6d97396782fe3a0df89be54f76ddccf1a 100644 (file)
@@ -55,8 +55,8 @@ static ssize_t internal_decode_pair_value(TALLOC_CTX *ctx, fr_pair_list_t *head,
        /*
         *      Zero length is fine here
         */
-       slen = fr_value_box_from_network_dbuff(vp, &vp->data, vp->da->type, vp->da,
-                                              &work_dbuff, fr_dbuff_len(&work_dbuff), tainted);
+       slen = fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                        &work_dbuff, fr_dbuff_len(&work_dbuff), tainted);
        if (slen < 0) {
                talloc_free(vp);
                return slen;
index d6976a0dd7c3ec74306cb8b0f0cacbe5eced9d53..ccf6978e1f5fb2d97062edb061b040db15a1fdb5 100644 (file)
@@ -1682,7 +1682,8 @@ ssize_t fr_radius_decode_pair_value(TALLOC_CTX *ctx, fr_dcursor_t *cursor, fr_di
 
        default:
        decode:
-               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da, p, data_len, true) < 0) {
+               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                             &FR_DBUFF_TMP(p, data_len), data_len, true) < 0) {
                        /*
                         *      Paranoid loop prevention
                         */
index e5e30276f929c0034e3150e7b5b86d41789b0a12..69348f5fc5662d593f912139c143be014afcd45b 100644 (file)
@@ -224,7 +224,8 @@ int fr_vmps_decode(TALLOC_CTX *ctx, uint8_t const *data, size_t data_len, fr_dcu
                 *
                 *      @todo - if the attribute is malformed, create a "raw" one.
                 */
-               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da, ptr, attr_len, true) < 0) {
+               if (fr_value_box_from_network(vp, &vp->data, vp->da->type, vp->da,
+                                             &FR_DBUFF_TMP(ptr, attr_len), attr_len, true) < 0) {
                        talloc_free(vp);
                        return -1;
                }