From e611a6c9936e1b8f3011ade93cda598aead78e44 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Sat, 18 Sep 2021 09:50:09 -0400 Subject: [PATCH] move self-allocated numbers to be dict-specific which has fewer opportunities for collisions --- src/lib/util/dict_priv.h | 1 + src/lib/util/dict_util.c | 1 + src/lib/util/dict_validate.c | 14 +++++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib/util/dict_priv.h b/src/lib/util/dict_priv.h index ea305edcf0..88ffe60cd9 100644 --- a/src/lib/util/dict_priv.h +++ b/src/lib/util/dict_priv.h @@ -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 diff --git a/src/lib/util/dict_util.c b/src/lib/util/dict_util.c index e5c9e65c58..b05f397bcc 100644 --- a/src/lib/util/dict_util.c +++ b/src/lib/util/dict_util.c @@ -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; } diff --git a/src/lib/util/dict_validate.c b/src/lib/util/dict_validate.c index 47d070be00..a540495b85 100644 --- a/src/lib/util/dict_validate.c +++ b/src/lib/util/dict_validate.c @@ -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; } /* -- 2.47.2