]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
ensure that the data types in "foreach" are compatible
authorAlan T. DeKok <aland@freeradius.org>
Wed, 4 Sep 2024 14:58:05 +0000 (10:58 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 4 Sep 2024 15:27:31 +0000 (11:27 -0400)
src/lib/unlang/compile.c

index aaf27e09fcd89dae24858efefbd599aab8efc84c..c97ffd3bb39f6fdc869a7601380cee5ef48b8a57 100644 (file)
@@ -3356,7 +3356,18 @@ static unlang_t *compile_foreach(unlang_t *parent, unlang_compile_t *unlang_ctx,
                type = fr_table_value_by_str(fr_type_table, type_name, FR_TYPE_VOID);
                fr_assert(type != FR_TYPE_VOID);
 
-               if (type == FR_TYPE_NULL) type = da->type;
+               if (type == FR_TYPE_NULL) {
+                       type = da->type;
+
+               } else if (fr_type_is_leaf(type) != fr_type_is_leaf(da->type)) {
+               incompatible:
+                       cf_log_err(cs, "Incompatible data types in foreach variable (%s), and reference being looped over (%s)",
+                                  fr_type_to_str(type), fr_type_to_str(da->type));
+                       goto fail;
+
+               } else if (fr_type_is_structural(type) && (type != da->type)) {
+                       goto incompatible;
+               }
 
                variable_name = cf_section_argv(cs, 1);