]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
move self-allocated numbers to be dict-specific
authorAlan T. DeKok <aland@freeradius.org>
Sat, 18 Sep 2021 13:50:09 +0000 (09:50 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sat, 18 Sep 2021 13:50:09 +0000 (09:50 -0400)
which has fewer opportunities for collisions

src/lib/util/dict_priv.h
src/lib/util/dict_util.c
src/lib/util/dict_validate.c

index ea305edcf0d634cc1cb1c988c2c1a1715891bee7..88ffe60cd97422ecad4251b3bd12b0f837bd5000 100644 (file)
@@ -97,6 +97,7 @@ struct fr_dict {
        unsigned int            vsa_parent;             //!< varies with different protocols
        int                     default_type_size;      //!< for TLVs and VSAs
        int                     default_type_length;    //!< for TLVs and VSAs
+       unsigned int            self_allocated;         //!< track attribute numbers for self allocations
 
        dl_t                    *dl;                    //!< for validation
 
index e5c9e65c580f3e34913d132a841d749f167e786c..b05f397bcc9f6590301842ae1505b103ece8718c 100644 (file)
@@ -3102,6 +3102,7 @@ fr_dict_t *dict_alloc(TALLOC_CTX *ctx)
         */
        dict->default_type_size = 1;
        dict->default_type_length = 1;
+       dict->self_allocated = (1 << 24);
 
        return dict;
 }
index 47d070be0092fc4e41f0093061a6e9bbcc4fb690..a540495b85a836f72e25ba54569f9172c08c5588 100644 (file)
@@ -578,8 +578,12 @@ bool dict_attr_fields_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
        /******************** sanity check attribute number ********************/
 
        if (parent->flags.is_root) {
-               static unsigned int max_attr = UINT8_MAX + 1;
-
+               /*
+                *      The value -1 is the special flag for "self
+                *      allocated" numbers.  i.e. we want an
+                *      attribute, but we don't care what the number
+                *      is.
+                */
                if (*attr == -1) {
                        flags->internal = 1;
 
@@ -596,14 +600,14 @@ bool dict_attr_fields_valid(fr_dict_t *dict, fr_dict_attr_t const *parent,
                                fr_strerror_printf("Conflicting definition for attribute %s", name);
                                return false;
                        }
-                       *attr = ++max_attr;
+                       *attr = ++dict->self_allocated;
 
                } else if (*attr <= 0) {
                        fr_strerror_printf("ATTRIBUTE number %i is invalid, must be greater than zero", *attr);
                        return false;
 
-               } else if ((unsigned int) *attr > max_attr) {
-                       max_attr = *attr;
+               } else if ((unsigned int) *attr > dict->self_allocated) {
+                       dict->self_allocated = *attr;
                }
 
                /*