]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
forbid [*] and [#] on the LHS of edit assignments
authorAlan T. DeKok <aland@freeradius.org>
Tue, 30 Aug 2022 16:47:19 +0000 (12:47 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 30 Aug 2022 16:47:19 +0000 (12:47 -0400)
and update the scripts in all.mk to handle [*] in output

src/lib/unlang/compile.c
src/tests/keywords/all.mk
src/tests/keywords/assign-empty-rhs-error [moved from src/tests/keywords/assign_error with 100% similarity]
src/tests/keywords/assign-star-error [new file with mode: 0644]
src/tests/keywords/join
src/tests/keywords/xlat-alternation
src/tests/keywords/xlat-alternation-fail-then-func
src/tests/keywords/xlat-attr-index

index 9b73b95ca914e71f36c2c1145f6215c832d30a4f..dbc13d3a42a5f74d152f6f709c81ea4b27ab8924 100644 (file)
@@ -1464,6 +1464,7 @@ static unlang_t *compile_edit_section(unlang_t *parent, unlang_compile_t *unlang
        fr_token_t              op;
        ssize_t                 slen;
        fr_dict_attr_t const    *parent_da;
+       int                     num;
 
        tmpl_rules_t            t_rules;
 
@@ -1551,6 +1552,15 @@ static unlang_t *compile_edit_section(unlang_t *parent, unlang_compile_t *unlang
                }
        }
 
+       /*
+        *      Can't assign to [*] or [#]
+        */
+       num = tmpl_num(map->lhs);
+       if ((num == NUM_ALL) || (num == NUM_COUNT)) {
+               cf_log_err(cs, "Invalid array reference in %s", name);
+               goto fail;
+       }
+
        /*
         *      Do basic sanity checks and resolving.
         */
@@ -1578,6 +1588,7 @@ static unlang_t *compile_edit_pair(unlang_t *parent, unlang_compile_t *unlang_ct
        unlang_edit_t           *edit, *edit_free;
        unlang_t                *c = NULL, *out = UNLANG_IGNORE;
        map_t                   *map;
+       int                     num;
 
        tmpl_rules_t            t_rules;
        fr_token_t              op;
@@ -1633,6 +1644,15 @@ static unlang_t *compile_edit_pair(unlang_t *parent, unlang_compile_t *unlang_ct
                return NULL;
        }
 
+       /*
+        *      Can't assign to [*] or [#]
+        */
+       num = tmpl_num(map->lhs);
+       if ((num == NUM_ALL) || (num == NUM_COUNT)) {
+               cf_log_err(cp, "Invalid array reference in %s", map->lhs->name);
+               goto fail;
+       }
+
        /*
         *      Do basic sanity checks and resolving.
         */
index 5074ddf988d9dbeaca0903eca4f4dd785acf00aa..10303f3684d0e8251ecb89ab3c9b7985b52a29c9 100644 (file)
@@ -117,7 +117,7 @@ $(OUTPUT)/%: $(DIR)/% $(TEST_BIN_DIR)/unit_test_module | $(KEYWORD_RADDB) $(KEYW
                        rm -f $(BUILD_DIR)/tests/test.keywords; \
                        exit 1; \
                fi; \
-               FOUND=$$(grep -E '^(Error : )?src/tests/keywords/$(notdir $@)' $@.log | head -1 | sed 's/.*\[//;s/\].*//'); \
+               FOUND=$$(grep 'Error : src/tests/keywords/' $@.log | head -1 | sed 's/]:.*//;s/.*\[//;s/\].*//'); \
                EXPECTED=$$(grep -n ERROR $< | sed 's/:.*//'); \
                if [ "$$EXPECTED" != "$$FOUND" ]; then \
                        cat $@.log; \
diff --git a/src/tests/keywords/assign-star-error b/src/tests/keywords/assign-star-error
new file mode 100644 (file)
index 0000000..3b0138d
--- /dev/null
@@ -0,0 +1,4 @@
+#
+#  We might allow this later.  But for now, the code doesn't implement it, so we don't allow it.
+#
+&User-Name[*] = "foo" # ERROR
index a123d116dbf6901a318dc8f7698bc00f9118ca0d..26bc129d297b44cbd80a7012183a5995d4798479 100644 (file)
@@ -1,5 +1,5 @@
 #
-# PRE: update if concat
+# PRE: if concat
 #
 &request -= &Packet-Type[*]
 
index 25e00a0111024d7292ee516857a51f826a7abcdd..845f9403bfc4c3c12cf8f7683545537877a18097 100644 (file)
@@ -1,19 +1,14 @@
 #
-# PRE: update
+# PRE:
 #
 
-update request {
-       &Tmp-String-0 := "foo"
-       &Tmp-String-1 := "bar"
-}
+&Tmp-String-0 := "foo"
+&Tmp-String-1 := "bar"
 
 #
 #  First choice
 #
-update request {
-       &Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]}}"
-}
-
+&Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]}}"
 if (&Tmp-String-2[0] != 'foo') {
        fail
 }
@@ -21,12 +16,8 @@ if (&Tmp-String-2[0] != 'foo') {
 #
 #  Second choice
 #
-update request {
-       &Tmp-String-0 !* ANY
-}
-update request {
-       &Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]}}"
-}
+&request -= &Tmp-String-0[*]
+&Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]}}"
 if (&Tmp-String-2[0] != 'bar') {
        fail
 }
@@ -34,9 +25,7 @@ if (&Tmp-String-2[0] != 'bar') {
 #
 #  Multiple things in an alternation
 #
-update request {
-       &Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]} foo}"
-}
+&Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]} foo}"
 if (&Tmp-String-2[0] != 'bar foo') {
        fail
 }
@@ -44,12 +33,8 @@ if (&Tmp-String-2[0] != 'bar foo') {
 #
 #  Everything null
 #
-update request {
-       &Tmp-String-1 !* ANY
-}
-update request {
-       &Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]}}"
-}
+&request -= &Tmp-String-1[*]
+&Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]}}"
 if (!&Tmp-String-2[0] || (&Tmp-String-2[0] != "")) {
        fail
 }
index f4b1dc98b91d43ba77706ce1b6ab00ab0957d2cc..9cb9215061552d9f65d1ccc91625c1e5088c596e 100644 (file)
@@ -1,16 +1,9 @@
-#
-# PRE: update
-#
-
 #
 #  Everything null
 #
-update request {
-       &Tmp-String-0 !* ANY
-       &Tmp-String-1 !* ANY
-}
-update request {
-       &Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]}}%(delay_10s:)"
-}
+&request -= &Tmp-String-0[*]
+&request -= &Tmp-String-1[*]
+
+&Tmp-String-2 := "%{%{Tmp-String-0[0]}:-%{Tmp-String-1[0]}}%(delay_10s:)"
 
 success
index 039f465663e140cd566d2521a776a6eb4f182140..c2cb4263694b0690fc9a454b8eb49903267f11f0 100644 (file)
@@ -1,17 +1,12 @@
-#
-# PRE: update
-#
-
-update request {
-       &Tmp-IP-Address-0 := 192.0.2.1
-       &Tmp-IP-Address-0 += 192.0.2.2
+&request += {
+       &Tmp-IP-Address-0 = 192.0.2.1
+       &Tmp-IP-Address-0 = 192.0.2.2
 }
-
 if ("%{Tmp-IP-Address-0[#]}" != 2) {
        test_fail
 }
 
-if (("%{Tmp-IP-Address-0[0]}" != 192.0.2.1) || ("%{Tmp-IP-Address-0[1]}" != 192.0.2.2)) {
+if ((&Tmp-IP-Address-0[0] != 192.0.2.1) || ("%{Tmp-IP-Address-0[1]}" != 192.0.2.2)) {
        test_fail
 }