]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
check at compile time for invalid assignments
authorAlan T. DeKok <aland@freeradius.org>
Tue, 7 Sep 2021 15:23:42 +0000 (11:23 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 7 Sep 2021 15:26:37 +0000 (11:26 -0400)
src/lib/server/map.c
src/tests/keywords/sign [new file with mode: 0644]

index 118d0f8e157257aa4a74047da6ddc978d9c7233f..49bf6d48f82d8361483e7f6d591ca6d50f6ccd9e 100644 (file)
@@ -194,6 +194,18 @@ int map_afrom_cp(TALLOC_CTX *ctx, map_t **out, map_t *parent, CONF_PAIR *cp,
                goto error;
        }
 
+       /*
+        *      If we know that the assignment is forbidden, then fail early.
+        */
+       if (tmpl_is_attr(map->lhs) && tmpl_is_data(map->rhs)) {
+               fr_dict_attr_t const *da = tmpl_da(map->lhs);
+
+               if (tmpl_cast_in_place(map->rhs, da->type, da) < 0) {
+                       cf_log_err(cp, "Invalid assignment - %s", fr_strerror());
+                       goto error;
+               }
+       }
+
        MAP_VERIFY(map);
 
        *out = map;
diff --git a/src/tests/keywords/sign b/src/tests/keywords/sign
new file mode 100644 (file)
index 0000000..f3cb711
--- /dev/null
@@ -0,0 +1,8 @@
+#
+#  PRE: update if
+#
+update request {
+       &Tmp-Integer-0 := -1000  # ERROR
+}
+
+test_fail