]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
update behavior of :=
authorAlan T. DeKok <aland@freeradius.org>
Mon, 21 Aug 2023 21:15:19 +0000 (17:15 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 21 Aug 2023 21:15:44 +0000 (17:15 -0400)
if RHS expansion fails, it still nukes all of the LHS

doc/antora/modules/reference/pages/unlang/edit.adoc
src/lib/unlang/edit.c
src/tests/keywords/edit-set-fail [new file with mode: 0644]

index 76a6ce24f9947481c11c618d152976fe3badb0c8..264706e4eca51b0b1f79257dab613670def17f28 100644 (file)
@@ -356,7 +356,7 @@ change the attribute _value_.
 |=====
 | Operator | Description
 | =        | Set the attribute to the contents of the _<rhs>_, if the _<attribute>_ does not exist.  If the attribute already exists, nothing is done.  If the attribute does not exist, it is created, and the contents set to the value of the _<rhs>_
-| :=       | Override the attribute with the contents with the _<rhs>_.  If the attribute already exists, its value is over-written.  If the attribute does not exist, it is created, and the contents set to thex value of the _<rhs>_
+| :=       | Delete all existing copies of the named attribute, and create a new attribute with the contents set to the value of the _<rhs>_
 | +=       | Perform addition.  The contents of the _<rhs>_ are added to the value of the _<attribute>_.
 | -=       | Perform subtraction. The contents of the _<rhs>_ are subtracted from the value of the _<attribute>_.
 | *=       | Perform multiplication.  The value of the _<attribute>_ is multiplied by the contents of the _<rhs>_.
index c3f6a357112538120b681c2b617c7b8706680aec..e24c26cd0dd6a5dd3f336ba41d488d979fd2d32b 100644 (file)
@@ -582,7 +582,7 @@ static int apply_edits_to_leaf(request_t *request, unlang_frame_state_edit_t *st
                pair = true;
        }
 
-       if (!box) {
+       if (!box && (map->op != T_OP_SET)) {
                RWDEBUG("%s %s ... - Assignment failed - No value on right-hand side", map->lhs->name, fr_tokens[map->op]);
                return -1;
        }
@@ -630,6 +630,11 @@ static int apply_edits_to_leaf(request_t *request, unlang_frame_state_edit_t *st
                fr_dict_attr_t const *da = tmpl_attr_tail_da(current->lhs.vpt);
                fr_pair_t *vp;
 
+               if (!box) {
+                       RDEBUG2("%s %s ...", current->lhs.vpt->name, fr_tokens[map->op]);
+                       goto done;
+               }
+
                /*
                 *      Something went wrong creating the value, it's a failure.  Note that we fail _all_
                 *      subsequent assignments, too.
diff --git a/src/tests/keywords/edit-set-fail b/src/tests/keywords/edit-set-fail
new file mode 100644 (file)
index 0000000..64104c2
--- /dev/null
@@ -0,0 +1,25 @@
+#
+#  Tests the ":=" operator where the RHS expansion fails.
+#
+#  It should still nuke the LHS attributes
+#
+
+&NAS-Port := 1812
+if !(&NAS-Port == 1812) {
+       test_fail
+}
+
+#
+#  Service-Type doesn't exist, so the ":=" means "delete everything"
+#
+&NAS-Port := %(integer:%{Service-Type})
+
+#
+#  This should no longer exist.
+#
+if &NAS-Port {
+       test_fail
+}
+
+
+success