]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean up and centralize checks for arrays
authorAlan T. DeKok <aland@freeradius.org>
Fri, 18 Mar 2022 23:55:03 +0000 (19:55 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 18 Mar 2022 23:55:03 +0000 (19:55 -0400)
src/lib/util/dict_validate.c

index b23c1de66cf2e73b7bb29dfb887d3acb0f5bc4ba..03bd829b146e122ba310554a88e9dd799ba4ce7a 100644 (file)
@@ -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.
         */