]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean up corner case for loading name
authorAlan T. DeKok <aland@freeradius.org>
Fri, 26 Jan 2024 21:46:13 +0000 (16:46 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 26 Jan 2024 21:46:13 +0000 (16:46 -0500)
src/lib/util/dict_fixup.c
src/lib/util/dict_fixup_priv.h
src/lib/util/dict_tokenize.c

index 37ee7a00263a4460dadd623441b53492dae9afb7..4ac52e1a9157d581031f260a4c233d5248191fcc 100644 (file)
@@ -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++;
        }
 
        /*
index 2ae5326e8ccb97ee549e7f947774d2faf18a7a44..3afd1ba4a0ee002c02f908a190a720780497674c 100644 (file)
@@ -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,
index 9ddead8d7a028ba66e2cb19271fe2022af058745..13f2b0bce5576f0c9b5049c0a46fa1af2b6ccb8a 100644 (file)
@@ -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;