From: Alan T. DeKok Date: Fri, 26 Jan 2024 21:46:13 +0000 (-0500) Subject: clean up corner case for loading name X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44cb7c60bd8cbe7c119eeabece0da9d3fca68c92;p=thirdparty%2Ffreeradius-server.git clean up corner case for loading name --- diff --git a/src/lib/util/dict_fixup.c b/src/lib/util/dict_fixup.c index 37ee7a00263..4ac52e1a915 100644 --- a/src/lib/util/dict_fixup.c +++ b/src/lib/util/dict_fixup.c @@ -202,13 +202,12 @@ static inline CC_HINT(always_inline) int dict_fixup_enumv_apply(UNUSED dict_fixu * @param[in] line this fixup relates to. * @param[in] da The group dictionary attribute. * @param[in] ref OID string representing what the group references. - * @param[in] ref_len Length of the reference string. * @return * - 0 on success. * - -1 on out of memory. */ int dict_fixup_group(dict_fixup_ctx_t *fctx, char const *filename, int line, - fr_dict_attr_t *da, char const *ref, size_t ref_len) + fr_dict_attr_t *da, char const *ref) { dict_fixup_group_t *fixup; @@ -219,7 +218,7 @@ int dict_fixup_group(dict_fixup_ctx_t *fctx, char const *filename, int line, } *fixup = (dict_fixup_group_t) { .da = da, - .ref = talloc_bstrndup(fixup, ref, ref_len) + .ref = talloc_strdup(fixup, ref), }; return dict_fixup_common(filename, line, &fctx->group, &fixup->common); @@ -239,11 +238,13 @@ static fr_dict_attr_t const *dict_find_or_load_reference(fr_dict_t **dict_def, c da = fr_dict_attr_by_oid(NULL, fr_dict_root(*dict_def), ref); if (da) return da; + invalid: fr_strerror_printf("Invalid attribute reference '%s' at %s[%d]", ref, fr_cwd_strip(filename), line); return NULL; } + fr_assert(ref[1] == '.'); name = ref + 2; /* already checked when we insert it */ /* @@ -281,12 +282,13 @@ static fr_dict_attr_t const *dict_find_or_load_reference(fr_dict_t **dict_def, c } name = p + 1; + } else { /* * The foreign dictionary was loaded by someone * else, try to resolve the attribute. */ - name += slen + 1; + name += slen; if (!*name) { /* @@ -295,6 +297,9 @@ static fr_dict_attr_t const *dict_find_or_load_reference(fr_dict_t **dict_def, c *dict_def = dict; return dict->root; } + + if (*name != '.') goto invalid; + name++; } /* diff --git a/src/lib/util/dict_fixup_priv.h b/src/lib/util/dict_fixup_priv.h index 2ae5326e8cc..3afd1ba4a0e 100644 --- a/src/lib/util/dict_fixup_priv.h +++ b/src/lib/util/dict_fixup_priv.h @@ -44,7 +44,7 @@ int dict_fixup_enumv(dict_fixup_ctx_t *fctx, char const *filename, int line, fr_dict_attr_t const *parent); int dict_fixup_group(dict_fixup_ctx_t *fctx, char const *filename, int line, - fr_dict_attr_t *da, char const *ref, size_t ref_len); + fr_dict_attr_t *da, char const *ref); int dict_fixup_clone(dict_fixup_ctx_t *fctx, char const *filename, int line, fr_dict_attr_t *parent, fr_dict_attr_t *da, diff --git a/src/lib/util/dict_tokenize.c b/src/lib/util/dict_tokenize.c index 9ddead8d7a0..13f2b0bce55 100644 --- a/src/lib/util/dict_tokenize.c +++ b/src/lib/util/dict_tokenize.c @@ -830,7 +830,7 @@ set: */ add_fixup: if (dict_fixup_group(&ctx->fixup, CURRENT_FRAME(ctx)->filename, CURRENT_FRAME(ctx)->line, - UNCONST(fr_dict_attr_t *, da), ref, talloc_array_length(ref) - 1) < 0) goto fail; + UNCONST(fr_dict_attr_t *, da), ref) < 0) goto fail; talloc_free(ref); return 0;