From: Alan T. DeKok Date: Mon, 21 Aug 2023 21:15:19 +0000 (-0400) Subject: update behavior of := X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f5df30fe716b0962d900db5f813db6287841d9f;p=thirdparty%2Ffreeradius-server.git update behavior of := if RHS expansion fails, it still nukes all of the LHS --- diff --git a/doc/antora/modules/reference/pages/unlang/edit.adoc b/doc/antora/modules/reference/pages/unlang/edit.adoc index 76a6ce24f99..264706e4eca 100644 --- a/doc/antora/modules/reference/pages/unlang/edit.adoc +++ b/doc/antora/modules/reference/pages/unlang/edit.adoc @@ -356,7 +356,7 @@ change the attribute _value_. |===== | Operator | Description | = | Set the attribute to the contents of the __, if the __ 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 __ -| := | Override the attribute with the contents with the __. 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 __ +| := | Delete all existing copies of the named attribute, and create a new attribute with the contents set to the value of the __ | += | Perform addition. The contents of the __ are added to the value of the __. | -= | Perform subtraction. The contents of the __ are subtracted from the value of the __. | *= | Perform multiplication. The value of the __ is multiplied by the contents of the __. diff --git a/src/lib/unlang/edit.c b/src/lib/unlang/edit.c index c3f6a357112..e24c26cd0dd 100644 --- a/src/lib/unlang/edit.c +++ b/src/lib/unlang/edit.c @@ -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 index 00000000000..64104c2039b --- /dev/null +++ b/src/tests/keywords/edit-set-fail @@ -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