]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
forbid array references in sublists
authorAlan T. DeKok <aland@freeradius.org>
Wed, 16 Nov 2022 18:02:40 +0000 (13:02 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 17 Nov 2022 12:34:56 +0000 (07:34 -0500)
&list := {
&foo[1] = "bar"
}

The edit code does not support this, because it doesn't really
make a lot of sense.  If we do need to support it, then the edit
code needs to be updated to support it.

Note that we can already do

&list.foo[1] = "bar"

so this limitation isn't much of an issue.  The problem comes when
doing multiple attribute assignments, and those using array indexes
inside of a sublist.  What does it mean when we do

&list := {
&foo[0] = "bar"
&foo[1] = "baz"
&foo[0] = "ugh"
}

What the heck is going on here?  The real answer is "don't do that"

src/lib/unlang/compile.c

index e99ec0c4eec06fafd5febd136a4a61f8797e76f8..57a417502ebd6c75a0ef1b5c1ad49f9c5298bb3e 100644 (file)
@@ -1820,9 +1820,23 @@ static unlang_t *compile_edit_section(unlang_t *parent, unlang_compile_t *unlang
         */
        parent_da = tmpl_da(map->lhs);
        if (fr_type_is_structural(parent_da->type)) {
+               map_t *child;
+
                if (map_afrom_cs(map, &map->child, cs, &t_rules, &t_rules, unlang_fixup_edit, map, 256) < 0) {
                        goto fail;
                }
+
+               /*
+                *      As a set of fixups... we can't do array references in -=
+                */
+               for (child = map_list_head(&map->child); child != NULL; child = map_list_next(&map->child, child)) {
+                       if (!tmpl_is_attr(child->lhs)) continue;
+
+                       if (tmpl_num(child->lhs) != NUM_UNSPEC) {
+                               cf_log_err(child->ci, "Cannot use array references and values when deleting from a list");
+                               goto fail;
+                       }
+               }
        } else {
                /*
                 *      &foo := { a, b, c }