]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow &foo := {} to mean "delete leaf attributes"
authorAlan T. DeKok <aland@freeradius.org>
Tue, 10 Oct 2023 00:45:53 +0000 (20:45 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 10 Oct 2023 00:45:53 +0000 (20:45 -0400)
because if the RHS is a dynamic expansion which returns no values,
that's what it means there

src/lib/unlang/compile.c
src/lib/unlang/edit.c
src/tests/keywords/edit-leaf-delete [new file with mode: 0644]
src/tests/keywords/edit-leaf-error [new file with mode: 0644]

index de0c07eae22e7298ac9f47f92c04167755aa7fd8..3003b84f5c4db91048f52f8102df9fe6f5a970df 100644 (file)
@@ -1586,6 +1586,12 @@ static unlang_t *compile_edit_section(unlang_t *parent, unlang_compile_t *unlang
                if (map_list_afrom_cs(map, &map->child, cs, &t_rules, NULL, NULL, 256) < 0) {
                        goto fail;
                }
+
+               if ((map->op != T_OP_SET) && !map_list_num_elements(&map->child)) {
+                       cf_log_err(cs, "Cannot use operator '%s' for assigning empty list to '%s' data type.",
+                                  fr_tokens[map->op], fr_type_to_str(parent_da->type));
+                       goto fail;
+               }
        }
        /*
         *      Do basic sanity checks and resolving.
index 03b081874b04f63f9b7efd25bffe772a8689064d..be329ea928eb250edef318d925669c734b65c196 100644 (file)
@@ -980,8 +980,8 @@ static int expand_rhs_list(request_t *request, unlang_frame_state_edit_t *state,
         *      Fast path: child is empty, we don't need to do anything.
         */
        if (fr_dlist_empty(&map->child.head)) {
-               if (fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type)) {
-                       REDEBUG("%s[%d] Cannot assign empty list to a normal data type", MAP_INFO);
+               if (fr_type_is_leaf(tmpl_attr_tail_da(current->lhs.vpt)->type) && (map->op != T_OP_SET)) {
+                       REDEBUG("%s[%d] Cannot assign a list to the '%s' data type", MAP_INFO, fr_type_to_str(tmpl_attr_tail_da(current->lhs.vpt)->type));
                        return -1;
                }
 
diff --git a/src/tests/keywords/edit-leaf-delete b/src/tests/keywords/edit-leaf-delete
new file mode 100644 (file)
index 0000000..6a0b348
--- /dev/null
@@ -0,0 +1,17 @@
+uint32 foo
+
+&foo := 42
+
+if !(&foo == 42) {
+       test_fail
+}
+
+#
+#  This is "delete"
+#
+&foo := {}
+
+if &foo {
+       test_fail
+}
+success
diff --git a/src/tests/keywords/edit-leaf-error b/src/tests/keywords/edit-leaf-error
new file mode 100644 (file)
index 0000000..db241bf
--- /dev/null
@@ -0,0 +1,9 @@
+uint32 foo
+
+&foo := 42
+
+if !(&foo == 42) {
+       test_fail
+}
+
+&foo += {}     # ERROR not allowed!