From: Alan T. DeKok Date: Fri, 15 Jan 2021 19:26:37 +0000 (-0500) Subject: clean up final uses of dict_attr_size X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e2163d4c08d6da9673d782a032ec3ef4d66164d;p=thirdparty%2Ffreeradius-server.git clean up final uses of dict_attr_size the struct validation code now checks if (a) the da contains a known fixed size, or (b) it's a FR_TYPE_VALUE. That covers the same situations as before. It still doesn't allow for variable-sized fields like dns labels, but that will have to be another step. now that dict_attr_size isn't used, it's removed. --- diff --git a/src/lib/util/dict.h b/src/lib/util/dict.h index f2ee54d5285..e65f3573c44 100644 --- a/src/lib/util/dict.h +++ b/src/lib/util/dict.h @@ -109,15 +109,6 @@ enum { #define da_is_bit_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_BIT_FIELD)) #define da_is_length_field(_da) ((_da)->flags.extra && ((_da)->flags.subtype == FLAG_LENGTH_UINT16)) -extern const size_t dict_attr_sizes[FR_TYPE_MAX + 1][2]; - -#define min_size(_type) (dict_attr_sizes[_type][0]) -#define max_size(_type) (dict_attr_sizes[_type][1]) - -static inline bool is_fixed_size(fr_type_t type) -{ - return min_size(type) == max_size(type); -} /** Extension identifier * diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index 6252ebff38c..974be909b63 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -56,42 +56,6 @@ fr_table_num_ordered_t const date_precision_table[] = { }; size_t date_precision_table_len = NUM_ELEMENTS(date_precision_table); - -/** Map data types to min / max data sizes - */ -size_t const dict_attr_sizes[FR_TYPE_MAX + 1][2] = { - [FR_TYPE_INVALID] = {~0, 0}, //!< Ensure array starts at 0 (umm?) - - [FR_TYPE_STRING] = {0, ~0}, - [FR_TYPE_OCTETS] = {0, ~0}, - - [FR_TYPE_IPV4_ADDR] = {4, 4}, - [FR_TYPE_IPV4_PREFIX] = {6, 6}, - [FR_TYPE_IPV6_ADDR] = {16, 16}, - [FR_TYPE_IPV6_PREFIX] = {2, 18}, - [FR_TYPE_COMBO_IP_ADDR] = {4, 16}, - [FR_TYPE_IFID] = {8, 8}, - [FR_TYPE_ETHERNET] = {6, 6}, - - [FR_TYPE_BOOL] = {1, 1}, - [FR_TYPE_UINT8] = {1, 1}, - [FR_TYPE_UINT16] = {2, 2}, - [FR_TYPE_UINT32] = {4, 4}, - [FR_TYPE_UINT64] = {8, 8}, - [FR_TYPE_SIZE] = {sizeof(size_t), sizeof(size_t)}, - [FR_TYPE_INT32] = {4, 4}, - - [FR_TYPE_DATE] = {4, 4}, - [FR_TYPE_TIME_DELTA] = {4, 4}, - - [FR_TYPE_TLV] = {2, ~0}, - [FR_TYPE_STRUCT] = {1, ~0}, - - [FR_TYPE_VSA] = {4, ~0}, - - [FR_TYPE_MAX] = {~0, 0} //!< Ensure array covers all types. -}; - /** Characters allowed in dictionary names * */ diff --git a/src/lib/util/dict_validate.c b/src/lib/util/dict_validate.c index e635dac5406..e89b33d714e 100644 --- a/src/lib/util/dict_validate.c +++ b/src/lib/util/dict_validate.c @@ -506,8 +506,11 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, * @todo - allow dns_label encoding as * the first member. */ - if ((max_size(sibling->type) == ~(size_t) 0) && - (sibling->flags.length == 0)) { + if (sibling->flags.length == 0) switch (sibling->type) { + case FR_TYPE_VALUE: + break; + + default: fr_strerror_const("Only the last child of a 'struct' attribute can have variable length"); return false; }