From: Alan T. DeKok Date: Fri, 18 Mar 2022 23:55:03 +0000 (-0400) Subject: clean up and centralize checks for arrays X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be090abd0ba1c47dc65195160e4f561165f7d9c5;p=thirdparty%2Ffreeradius-server.git clean up and centralize checks for arrays --- diff --git a/src/lib/util/dict_validate.c b/src/lib/util/dict_validate.c index b23c1de66cf..03bd829b146 100644 --- a/src/lib/util/dict_validate.c +++ b/src/lib/util/dict_validate.c @@ -97,10 +97,11 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, } /* - * Only some data types can be in arrays. + * Only some data types can be in arrays, because we need + * to be able to decode the various array members. */ if (flags->array) { - switch (type) { + if (!flags->is_known_width) switch (type) { default: fr_strerror_printf("The 'array' flag cannot be used with attributes of type '%s'", fr_type_to_str(type)); @@ -115,9 +116,23 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, case FR_TYPE_UINT32: case FR_TYPE_DATE: case FR_TYPE_TIME_DELTA: + break; + case FR_TYPE_STRING: case FR_TYPE_OCTETS: + if (!flags->length) { + fr_strerror_const("Variable length attributes cannot be marked as 'array'"); + return false; + } + + flags->is_known_width = 1; + break; + case FR_TYPE_STRUCT: + /* + * If we have arrays of structs, then the structure MUST be known width. + */ + flags->is_known_width = 1; break; } @@ -229,11 +244,6 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, return false; } - /* - * If we have arrays of structs, then the structure MUST be known width. - */ - flags->is_known_width |= flags->array; - ALLOW_FLAG(extra); ALLOW_FLAG(subtype); ALLOW_FLAG(array); @@ -449,8 +459,6 @@ bool dict_attr_flags_valid(fr_dict_t *dict, fr_dict_attr_t const *parent, break; } - flags->is_known_width |= (flags->length > 0); /* for fixed-size string / octets */ - /* * type_size is used to limit the maximum attribute number, so it's checked first. */