]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
remove fr_radius_attr_len() and related checks
authorAlan T. DeKok <aland@freeradius.org>
Sun, 17 Apr 2022 05:50:50 +0000 (01:50 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 20 Apr 2022 13:13:50 +0000 (09:13 -0400)
we can just either (a) rely on the input dbuff to see when the
data is too long to encode, or (b) just check vp->vp_length

src/protocols/radius/base.c
src/protocols/radius/encode.c
src/protocols/radius/radius.h

index 561e4923a46027d46be74993fa6da5cb33577b26..89c7d1080a2a3dc539efbad488cd95a5fcab1606 100644 (file)
@@ -200,27 +200,6 @@ bool const fr_request_packets[FR_RADIUS_CODE_MAX + 1] = {
 };
 
 
-/** Return the on-the-wire length of an attribute value
- *
- * @param[in] vp to return the length of.
- * @return the length of the attribute.
- */
-size_t fr_radius_attr_len(fr_pair_t const *vp)
-{
-       switch (vp->vp_type) {
-       case FR_TYPE_VARIABLE_SIZE:
-               if (vp->da->flags.length) return vp->da->flags.length;  /* Variable type with fixed length */
-               return vp->vp_length;
-
-       case FR_TYPE_STRUCTURAL:
-               fr_assert_fail(NULL);
-               return 0;
-
-       default:
-               return fr_radius_attr_sizes[vp->vp_type][0];
-       }
-}
-
 /**  Do Ascend-Send / Recv-Secret calculation.
  *
  * The secret is hidden by xoring with a MD5 digest created from
index f0b29072f742793e5d2b8d847f0eb7394529e89d..0426af1072a580565c78d872934d4ec4eb50f06c 100644 (file)
@@ -451,20 +451,6 @@ static ssize_t encode_value(fr_dbuff_t *dbuff,
        fr_dbuff_marker(&src, &value_dbuff);
        fr_dbuff_marker(&dest, &value_dbuff);
 
-       /*
-        *      Set up the default sources for the data.
-        */
-       len = fr_radius_attr_len(vp);
-
-       /*
-        *      Invalid value, don't encode.
-        */
-       if (len > RADIUS_MAX_STRING_LENGTH) {
-               fr_strerror_printf("%s length of %zu bytes exceeds maximum value length",
-                                  vp->da->name, len);
-               return PAIR_ENCODE_SKIPPED;
-       }
-
        switch (da->type) {
                /*
                 *      IPv4 addresses are normal, but IPv6 addresses are special to RADIUS.
@@ -872,7 +858,7 @@ static ssize_t encode_concat(fr_dbuff_t *dbuff,
        FR_PROTO_STACK_PRINT(da_stack, depth);
 
        p = vp->vp_octets;
-       data_len = fr_radius_attr_len(vp);
+       data_len = vp->vp_length;
        fr_dbuff_marker(&hdr, &work_dbuff);
 
        while (data_len > 0) {
@@ -1510,17 +1496,15 @@ ssize_t fr_radius_encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *enc
                 */
        case FR_TYPE_STRING:
        case FR_TYPE_OCTETS:
-               if (fr_radius_attr_len(vp) != 0) break;
-
                /*
                 *      Zero-length strings are allowed for CUI
                 *      (thanks WiMAX!), and for
                 *      Message-Authenticator, because we will
                 *      automagically generate that one ourselves.
                 */
-               if (!fr_dict_attr_is_top_level(vp->da) ||
-                   ((vp->da->attr != FR_CHARGEABLE_USER_IDENTITY) &&
-                    (vp->da->attr != FR_MESSAGE_AUTHENTICATOR))) {
+               if ((vp->vp_length == 0) &&
+                   (vp->da != attr_chargeable_user_identity) &&
+                   (vp->da != attr_message_authenticator)) {
                        fr_dcursor_next(cursor);
                        fr_strerror_const("Zero length string attributes not allowed");
                        return PAIR_ENCODE_SKIPPED;
index 256e3d448818c5341c28ca53d36d4f9127d2b4c4..6a15ec9c6e15655c60bb273cb8785ed121221eb7 100644 (file)
@@ -108,8 +108,6 @@ enum {
 /*
  *     protocols/radius/base.c
  */
-size_t         fr_radius_attr_len(fr_pair_t const *vp);
-
 int            fr_radius_sign(uint8_t *packet, uint8_t const *original,
                               uint8_t const *secret, size_t secret_len) CC_HINT(nonnull (1,3));
 int            fr_radius_verify(uint8_t *packet, uint8_t const *original,