From: Alan T. DeKok Date: Tue, 7 Sep 2021 15:23:42 +0000 (-0400) Subject: check at compile time for invalid assignments X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69e214acfb4dde3507d424e1ac87dc32219e61cb;p=thirdparty%2Ffreeradius-server.git check at compile time for invalid assignments --- diff --git a/src/lib/server/map.c b/src/lib/server/map.c index 118d0f8e157..49bf6d48f82 100644 --- a/src/lib/server/map.c +++ b/src/lib/server/map.c @@ -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 index 00000000000..f3cb711dabb --- /dev/null +++ b/src/tests/keywords/sign @@ -0,0 +1,8 @@ +# +# PRE: update if +# +update request { + &Tmp-Integer-0 := -1000 # ERROR +} + +test_fail