From: Alan T. DeKok Date: Sat, 31 Aug 2024 13:56:08 +0000 (-0400) Subject: give warning on 'foreach' not using [*] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2b2add4b0166a70112c035a9fe4ba61efc7cd99;p=thirdparty%2Ffreeradius-server.git give warning on 'foreach' not using [*] --- diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index b673e00e4e..e30bbf6b80 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -3295,18 +3295,16 @@ static unlang_t *compile_foreach(unlang_t *parent, unlang_compile_t *unlang_ctx, goto fail; } - if ((tmpl_attr_tail_num(vpt) != NUM_ALL) && (tmpl_attr_tail_num(vpt) != NUM_UNSPEC)) { + if (tmpl_attr_tail_num(vpt) == NUM_UNSPEC) { + cf_log_warn(cs, "Attribute reference should be updated to use %s[*]", vpt->name); + tmpl_attr_rewrite_leaf_num(vpt, NUM_UNSPEC, NUM_ALL); + } + + if (tmpl_attr_tail_num(vpt) != NUM_ALL) { cf_log_err(cs, "MUST NOT use instance selectors in 'foreach'"); goto fail; } - /* - * Fix up the template to iterate over all instances of - * the attribute. In a perfect consistent world, users would do - * foreach &attr[*], but that's taking the consistency thing a bit far. - */ - tmpl_attr_rewrite_leaf_num(vpt, NUM_UNSPEC, NUM_ALL); - gext = unlang_group_to_foreach(g); gext->vpt = vpt;