]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
make flags.length 16 bits
authorAlan T. DeKok <aland@freeradius.org>
Sat, 23 Aug 2025 12:21:56 +0000 (08:21 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 23 Aug 2025 12:24:04 +0000 (08:24 -0400)
because fr_dict_attr_flags_t is 8 octets for alignment, so we still
have a few extra bytes to work with

src/lib/util/dict.h
src/lib/util/dict_tokenize.c

index 897afcf43df5862401294773487ba0459443ccf0..552a657feac631e5eae795538ca749469dd3c151 100644 (file)
@@ -118,7 +118,7 @@ typedef struct {
 
        unsigned int            local : 1;                      //!< is a local variable
 
-       unsigned int            has_fixup : 1;
+       unsigned int            has_fixup : 1;                  //! needs a fixup during dictionary parsing
 
        /*
         *      main: extra is set, then this field is is key, bit, or a uint16 length field.
@@ -128,18 +128,26 @@ typedef struct {
        uint8_t                 subtype;                        //!< protocol-specific values, OR key fields
 
        /*
-        *      Length in bytes for most attributes.
-        *      Length in bits for da_is_bit_field(da)
+        *      TLVs: Number of bytes in the "type" field for TLVs (typically 1, 2, or 4)
+        *
+        *      da_is_bit_field(da): offset in the byte where this bit
+        *      field ends.  This is only used as a caching mechanism
+        *      during parsing of the dictionaries.
+        *
+        *      time/time_delta: fr_time_res_t, which has 4 possible values.
+        *
+        *      otherwise: unused.
         */
-       uint8_t                 length;                         //!< length of the attribute
+       uint8_t                 type_size;                      //!< Type size for TLVs
 
        /*
-        *      TLVs: 1, 2, or 4.
-        *      date / time types: fr_time_res_t, which has 4 possible values.
-        *      bit fields: offset in the byte where this bit field ends, which is only
-        *      used as a caching mechanism during parsing of the dictionaries.
+        *      da_is_bit_field(da): Length of the field in bits.
+        *
+        *      TLV: Number of bytes in the "length" field
+        *
+        *      otherwise: Length in bytes
         */
-       uint8_t                 type_size;                      //!< For TLV2 and root attributes.
+       uint16_t                length;                         //!< length of the attribute
 } fr_dict_attr_flags_t;
 
 #define flag_time_res type_size
index 42ed7bc3a364b80ffe02e9a0698a942de573f0fb..16395e43150760658a3a5905b272363e3b0306ca 100644 (file)
@@ -368,9 +368,9 @@ static int dict_process_type_field(dict_tokenize_ctx_t *dctx, char const *name,
                }
 
                /*
-                *      "length" has to fit into a uint8_t field.
+                *      "length" has to fit into the flags.length field.
                 */
-               if ((length == 0) || (length > 255)) {
+               if ((length == 0) || (length > UINT16_MAX)) {
                        fr_strerror_printf("Invalid length for '%s[...]'", name);
                        return -1;
                }
@@ -1054,7 +1054,7 @@ static int dict_struct_finalise(dict_tokenize_ctx_t *dctx)
         *      If we have discovered that the structure has a fixed size, then update the da with that
         *      information.
         */
-       if (frame->struct_size <= 255) {
+       if (frame->struct_size < UINT16_MAX) {
                UNCONST(fr_dict_attr_t *, da)->flags.length = frame->struct_size;
        } /* else length 0 means "unknown / variable size / too large */