From: Alan T. DeKok Date: Tue, 10 Oct 2023 00:45:53 +0000 (-0400) Subject: allow &foo := {} to mean "delete leaf attributes" X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c1f6723ac2255eb76e0b3a6a8a85c7da734c740;p=thirdparty%2Ffreeradius-server.git allow &foo := {} to mean "delete leaf attributes" because if the RHS is a dynamic expansion which returns no values, that's what it means there --- diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index de0c07eae2..3003b84f5c 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -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. diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index 03b081874b..be329ea928 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -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 index 0000000000..6a0b348487 --- /dev/null +++ b/src/tests/keywords/edit-leaf-delete @@ -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 index 0000000000..db241bf53e --- /dev/null +++ b/src/tests/keywords/edit-leaf-error @@ -0,0 +1,9 @@ +uint32 foo + +&foo := 42 + +if !(&foo == 42) { + test_fail +} + +&foo += {} # ERROR not allowed!