]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Better errors
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 2 Oct 2020 19:47:04 +0000 (14:47 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 2 Oct 2020 19:47:04 +0000 (14:47 -0500)
src/lib/server/tmpl_tokenize.c
src/lib/util/dict_util.c

index 716ec39605886b74b51d2aeecd708728615d3e9f..437a13667ad7670758b9d0d20e4d7fa55083606f 100644 (file)
@@ -1319,6 +1319,7 @@ static inline int tmpl_attr_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t
        fr_dict_attr_t const    *da;
        fr_sbuff_marker_t       m_s;
        tmpl_attr_filter_t      filter;
+       fr_dict_attr_err_t      dict_err;
 
        fr_sbuff_marker(&m_s, name);
 
@@ -1343,14 +1344,26 @@ static inline int tmpl_attr_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t
         *      No parent means we need to go hunting through all the dictionaries
         */
        if (!parent) {
-               slen = fr_dict_attr_by_qualified_name_substr(NULL, &da,
+               slen = fr_dict_attr_by_qualified_name_substr(&dict_err, &da,
                                                             rules->dict_def, name, !rules->disallow_internal);
        /*
         *      Otherwise we're resolving in the context of the last component,
         *      or its reference in the case of group attributes.
         */
        } else {
-               slen = fr_dict_attr_child_by_name_substr(NULL, &da, parent, name, false);
+               slen = fr_dict_attr_child_by_name_substr(&dict_err, &da, parent, name, false);
+       }
+
+       /*
+        *      Fatal errors related to nesting...
+        */
+       switch (dict_err) {
+       case FR_DICT_ATTR_NO_CHILDREN:
+       case FR_DICT_ATTR_NOT_DESCENDENT:
+               goto error;
+
+       default:
+               break;
        }
 
        /*
index 1c19cab7a8d91515788eca6b216e612d4b465345..9635796470b74f07378b42e584a08976ae939fcc 100644 (file)
@@ -2109,6 +2109,22 @@ ssize_t fr_dict_attr_child_by_name_substr(fr_dict_attr_err_t *err,
 
        DA_VERIFY(parent);
 
+       /*
+        *      Check the parent can is a grouping attribute
+        */
+       switch (parent->type) {
+       case FR_TYPE_STRUCTURAL:
+               break;
+
+       default:
+               fr_strerror_printf("Parent (%s) is a %s, it cannot contain nested attributes",
+                                  parent->name,
+                                  fr_table_str_by_value(fr_value_box_type_table,
+                                                        parent->type, "?Unknown?"));
+               if (err) *err = FR_DICT_ATTR_NO_CHILDREN;
+               return 0;
+       }
+
        /*
         *      We return the child of the referenced attribute, and
         *      not of the "group" attribute.
@@ -2116,7 +2132,7 @@ ssize_t fr_dict_attr_child_by_name_substr(fr_dict_attr_err_t *err,
        if (parent->type == FR_TYPE_GROUP) parent = parent->ref;
 
        if (!parent->children) {
-               fr_strerror_printf("%s has no children", parent->name);
+               fr_strerror_printf("Parent (%s) has no children", parent->name);
                if (err) *err = FR_DICT_ATTR_NO_CHILDREN;
                return 0;
        }
@@ -2127,7 +2143,7 @@ ssize_t fr_dict_attr_child_by_name_substr(fr_dict_attr_err_t *err,
        if (is_direct_decendent) {
                if ((*out)->parent != parent) {
                not_decendent:
-                       fr_strerror_printf("%s is not a descendent of %s", parent->name, (*out)->name);
+                       fr_strerror_printf("%s is not a descendent of parent (%s)", parent->name, (*out)->name);
                        if (err) *err = FR_DICT_ATTR_NOT_DESCENDENT;
                        *out = NULL;
                        return 0;