From: Alan T. DeKok Date: Sat, 23 Aug 2025 12:21:56 +0000 (-0400) Subject: make flags.length 16 bits X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=97f940d23d85a88f0df4aef15ec0958794bd1338;p=thirdparty%2Ffreeradius-server.git make flags.length 16 bits because fr_dict_attr_flags_t is 8 octets for alignment, so we still have a few extra bytes to work with --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index 897afcf43d..552a657fea 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -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 diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index 42ed7bc3a3..16395e4315 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -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 */