]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Set PAIR_LIST_UNKNOWN = 0 to catch where the list is not explicitly set
authorNick Porter <nick@portercomputing.co.uk>
Thu, 12 Jan 2023 10:00:41 +0000 (10:00 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 9 Feb 2023 16:31:27 +0000 (10:31 -0600)
21 files changed:
src/bin/unit_test_attribute.c
src/bin/unit_test_map.c
src/bin/unit_test_module.c
src/lib/server/cf_file.c
src/lib/server/cf_parse.c
src/lib/server/map.c
src/lib/server/map_async.c
src/lib/server/tmpl_dcursor_tests.c
src/lib/server/tmpl_tokenize.c
src/lib/server/users_file.c
src/lib/server/virtual_servers.c
src/lib/unlang/compile.c
src/lib/unlang/edit.c
src/lib/unlang/xlat_builtin.c
src/lib/unlang/xlat_eval.c
src/listen/ldap_sync/proto_ldap_sync.c
src/modules/rlm_cache/rlm_cache.c
src/modules/rlm_exec/rlm_exec.c
src/modules/rlm_json/rlm_json.c
src/modules/rlm_ldap/rlm_ldap.c
src/modules/rlm_linelog/rlm_linelog.c

index adc8e21a868452c42aabf4806b3a5e3e49684c72..762d03d9c36c76ecd5bf9fdaddf1406a3a8eb8d3 100644 (file)
@@ -2833,6 +2833,7 @@ static size_t command_xlat_normalise(command_result_t *result, command_file_ctx_
                                        .attr = {
                                                .dict_def = cc->tmpl_rules.attr.dict_def ?
                                                cc->tmpl_rules.attr.dict_def : cc->config->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .allow_unresolved = cc->tmpl_rules.attr.allow_unresolved
                                        },
                                });
@@ -2869,6 +2870,7 @@ static size_t command_xlat_expr(command_result_t *result, command_file_ctx_t *cc
                                                        .dict_def = cc->tmpl_rules.attr.dict_def ?
                                                           cc->tmpl_rules.attr.dict_def : cc->config->dict,
                                                        .allow_unresolved = cc->tmpl_rules.attr.allow_unresolved,
+                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .list_as_attr = true,
                                                }
                                           });
@@ -2909,6 +2911,7 @@ static size_t command_xlat_purify(command_result_t *result, command_file_ctx_t *
                                                        .dict_def = cc->tmpl_rules.attr.dict_def ?
                                                           cc->tmpl_rules.attr.dict_def : cc->config->dict,
                                                        .allow_unresolved = cc->tmpl_rules.attr.allow_unresolved,
+                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .list_as_attr = true,
                                                   },
                                           });
@@ -2962,6 +2965,7 @@ static size_t command_xlat_argv(command_result_t *result, command_file_ctx_t *cc
                                          .attr = {
                                                  .dict_def = cc->tmpl_rules.attr.dict_def ?
                                                  cc->tmpl_rules.attr.dict_def : cc->config->dict,
+                                                 .list_def = PAIR_LIST_REQUEST,
                                                  .allow_unresolved = cc->tmpl_rules.attr.allow_unresolved
                                          },
                                  });
@@ -3344,6 +3348,8 @@ static command_file_ctx_t *command_ctx_alloc(TALLOC_CTX *ctx,
 
        cc->fuzzer_dir = -1;
 
+       cc->tmpl_rules.attr.list_def = PAIR_LIST_REQUEST;
+
        return cc;
 }
 
index 60f1ba8ad651a37ec73e5106baf19a97e7fa05ed..62d40d7cd57052d430ea6b8353a80bcefe3b4b26 100644 (file)
@@ -84,6 +84,7 @@ static int process_file(char const *filename)
        tmpl_rules_t    parse_rules = {
                .attr = {
                        .dict_def = dict_radius,
+                       .list_def = PAIR_LIST_REQUEST,
                        .allow_foreign = false, /* tests are in the RADIUS dictionary */
                }
        };
index b9f1de74e99f5832b2ac910f6c441acdd013d999..12065e49e17246afd1eb9f9189666241c41c9b84 100644 (file)
@@ -440,9 +440,10 @@ static bool do_xlats(fr_event_list_t *el, char const *filename, FILE *fp)
                                                                  &(tmpl_rules_t) {
                                                                          .attr = {
                                                                                  .dict_def = dict_protocol,
+                                                                                 .list_def = PAIR_LIST_REQUEST,
                                                                                  .allow_unresolved = true,
                                                                          }
-                                                                                 }
+                                                                 }
                                                                );
                        if (slen <= 0) {
                                talloc_free(xlat_ctx);
index 6a17f14526dc8035337f2f8d916407b28b71e6af..092659148aadc2efb82c067d9ff562c233e29cb0 100644 (file)
@@ -1499,6 +1499,7 @@ static CONF_ITEM *process_if(cf_stack_t *stack)
        t_rules = (tmpl_rules_t) {
                .attr = {
                        .dict_def = dict,
+                       .list_def = PAIR_LIST_REQUEST,
                        .allow_unresolved = true,
                        .allow_unknown = true
                }
index 32f5d20640360dc40bf135b95af48e881ada10c3..d3829eac207fa308af9fb3a48ae115ac97ebc61c 100644 (file)
@@ -222,6 +222,7 @@ int cf_pair_parse_value(TALLOC_CTX *ctx, void *out, UNUSED void *base, CONF_ITEM
                tmpl_t                  *vpt;
                static tmpl_rules_t     rules = {
                                                .attr = {
+                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .allow_unknown = true,
                                                        .allow_unresolved = true,
                                                        .allow_foreign = true
@@ -1221,6 +1222,7 @@ int cf_section_parse_pass2(void *base, CONF_SECTION *cs)
                                             &(tmpl_rules_t) {
                                                     .attr = {
                                                             .dict_def = dict,
+                                                            .list_def = PAIR_LIST_REQUEST,
                                                             .allow_unknown = false,
                                                             .allow_unresolved = false,
                                                             .allow_foreign = (dict == NULL)
index 30a4b79531bb53779e54ed0418954d444c0e342c..cd831828446da53edf5f88e6fd12e873f042b05b 100644 (file)
@@ -1781,6 +1781,7 @@ int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t f
                                           &(tmpl_rules_t){
                                                .attr = {
                                                        .dict_def = request->dict,
+                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .prefix = TMPL_ATTR_REF_PREFIX_NO
                                                }
                                           });
index fdb905e65e9718faa2903876467e10ff5cb230f0..656426dd19664ebf467f30cf81e4a5f40363926b 100644 (file)
@@ -323,6 +323,7 @@ int map_to_list_mod(TALLOC_CTX *ctx, vp_list_mod_t **out,
                                           &(tmpl_rules_t){
                                                .attr = {
                                                        .dict_def = request->dict,
+                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .prefix = TMPL_ATTR_REF_PREFIX_NO
                                                }
                                           });
index 1455605e67f1354a16fbc5c986908bcc362fd080..997880993651984cabb40a4e9dda90ef79b51674 100644 (file)
@@ -133,11 +133,15 @@ typedef struct {
 static inline CC_HINT(always_inline)
 int _tmpl_setup_and_cursor_init(fr_pair_t **vp_out, tmpl_dcursor_vars_t *vars, request_t *request, char const *ref)
 {
-       tmpl_afrom_attr_substr(autofree, NULL, &vars->vpt, &FR_SBUFF_IN(ref, strlen(ref)), NULL, &(tmpl_rules_t){.attr = {.dict_def = test_dict}}); 
-       TEST_CHECK(vars->vpt!= NULL); 
-       TEST_MSG("Failed creating tmpl from %s: %s", ref, fr_strerror()); 
-       if (!vars->vpt) { 
-               *vp_out = NULL; 
+       tmpl_afrom_attr_substr(autofree, NULL, &vars->vpt, &FR_SBUFF_IN(ref, strlen(ref)), NULL, &(tmpl_rules_t){
+                       .attr = {
+                               .dict_def = test_dict,
+                               .list_def = PAIR_LIST_REQUEST,
+                       }});
+       TEST_CHECK(vars->vpt!= NULL);
+       TEST_MSG("Failed creating tmpl from %s: %s", ref, fr_strerror());
+       if (!vars->vpt) {
+               *vp_out = NULL;
                return -1;
        }
 
@@ -157,11 +161,15 @@ int _tmpl_setup_and_cursor_init(fr_pair_t **vp_out, tmpl_dcursor_vars_t *vars, r
 static inline CC_HINT(always_inline)
 int _tmpl_setup_and_cursor_build_init(fr_pair_t **vp_out, tmpl_dcursor_vars_t *vars, request_t *request, char const *ref)
 {
-       tmpl_afrom_attr_substr(autofree, NULL, &vars->vpt, &FR_SBUFF_IN(ref, strlen(ref)), NULL, &(tmpl_rules_t){.attr = {.dict_def = test_dict}}); 
-       TEST_CHECK(vars->vpt!= NULL); 
-       TEST_MSG("Failed creating tmpl from %s: %s", ref, fr_strerror()); 
-       if (!vars->vpt) { 
-               *vp_out = NULL; 
+       tmpl_afrom_attr_substr(autofree, NULL, &vars->vpt, &FR_SBUFF_IN(ref, strlen(ref)), NULL, &(tmpl_rules_t){
+                       .attr = {
+                               .dict_def = test_dict,
+                               .list_def = PAIR_LIST_REQUEST,
+                       }});
+       TEST_CHECK(vars->vpt!= NULL);
+       TEST_MSG("Failed creating tmpl from %s: %s", ref, fr_strerror());
+       if (!vars->vpt) {
+               *vp_out = NULL;
                return -1;
        }
 
index 874b0faa6a59b3a3270c94420ad6aebc621fbc64..155cfc392c0f3004fae389a8605a7b818717f8bf 100644 (file)
@@ -96,7 +96,9 @@ TMPL_REQUEST_REF_DEF(tmpl_request_def_parent, REQUEST_PARENT);
  * Defaults are used if a NULL rules pointer is passed to the parsing function.
  */
 static tmpl_rules_t const default_rules = {
-
+       .attr = {
+               .list_def = PAIR_LIST_REQUEST,
+       },
 };
 
 
@@ -4964,7 +4966,7 @@ void tmpl_verify(char const *file, int line, tmpl_t const *vpt)
                                                     fr_type_to_str(da->type));
                        }
 
-                       if (!vpt->rules.attr.list_as_attr && (tmpl_list(vpt) >= PAIR_LIST_UNKNOWN)) {
+                       if (!vpt->rules.attr.list_as_attr && ((tmpl_list(vpt) == PAIR_LIST_UNKNOWN) || tmpl_list(vpt) > PAIR_LIST_STATE)) {
                                fr_fatal_assert_fail("CONSISTENCY CHECK FAILED %s[%u]: TMPL_TYPE_ATTR "
                                                     "attribute \"%s\" has invalid list (%i)",
                                                     file, line, tmpl_attr_tail_da(vpt)->name, tmpl_list(vpt));
index 86d2420a76bb1073e694843855f07f125695c55a..176fedf0f0915915b71754ea45abab345618ed53 100644 (file)
@@ -272,6 +272,7 @@ int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR
                .attr = {
                        .dict_def = dict,
                        .prefix = TMPL_ATTR_REF_PREFIX_NO,
+                       .list_def = PAIR_LIST_REQUEST,
                        .disallow_qualifiers = true, /* for now, until more tests are made */
 
                        /*
@@ -288,6 +289,7 @@ int pairlist_read(TALLOC_CTX *ctx, fr_dict_t const *dict, char const *file, PAIR
                .attr = {
                        .dict_def = dict,
                        .prefix = TMPL_ATTR_REF_PREFIX_YES,
+                       .list_def = PAIR_LIST_REQUEST,
                        .disallow_qualifiers = true, /* for now, until rlm_files supports it */
                }
        };
index bda76a1b9517ea0a7e1a0a8ac655ebe499258056..bb7a0fedf2612f15859f490441fb2daafc54364f 100644 (file)
@@ -1224,10 +1224,13 @@ int virtual_servers_instantiate(void)
                 *      the process module.
                 */
                if (process->compile_list) {
-                       tmpl_rules_t            parse_rules;
+                       tmpl_rules_t            parse_rules = {
+                               .attr = {
+                                       .dict_def = *(process->dict),
+                                       .list_def = PAIR_LIST_REQUEST,
+                               },
+                       };
 
-                       memset(&parse_rules, 0, sizeof(parse_rules));
-                       parse_rules.attr.dict_def = *(process->dict);
                        fr_assert(parse_rules.attr.dict_def != NULL);
 
                        if (virtual_server_compile_sections(server_cs, process->compile_list, &parse_rules,
index 04c1bc4e3cc7b01ec9b30a20f774d7ec5719812d..a9377a6bf529e2b4a794b06f66a79886dccace39 100644 (file)
@@ -440,6 +440,7 @@ static bool pass2_fixup_cond_map(fr_cond_t *c, CONF_ITEM *ci, fr_dict_t const *d
                                         NULL,
                                         &(tmpl_rules_t){
                                                .attr = {
+                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .allow_unknown = true
                                                }
                                         });
@@ -2767,6 +2768,8 @@ static unlang_t *compile_section(unlang_t *parent, unlang_compile_t *unlang_ctx,
        unlang_t        *c;
        char const      *name1, *name2;
 
+       fr_assert(unlang_ctx->rules != NULL);
+       fr_assert(unlang_ctx->rules->attr.list_def != PAIR_LIST_UNKNOWN);
        /*
         *      We always create a group, even if the section is empty.
         */
@@ -3728,6 +3731,7 @@ static unlang_t *compile_if_subsection(unlang_t *parent, unlang_compile_t *unlan
                tmpl_rules_t t_rules = (tmpl_rules_t) {
                        .attr = {
                                .dict_def = xr_rules.tr_rules->dict_def,
+                               .list_def = PAIR_LIST_REQUEST,
                                .allow_unresolved = true,
                                .allow_unknown = true
                        }
index 15888b03f2c295748d17ecd5b6557c8636fec280..76d32faaf43d34d4675bfee507d8392b056385c5 100644 (file)
@@ -113,6 +113,7 @@ static int tmpl_attr_from_result(TALLOC_CTX *ctx, map_t const *map, edit_result_
                                   &(tmpl_rules_t){
                                        .attr = {
                                                .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .prefix = TMPL_ATTR_REF_PREFIX_NO
                                        }
                                   });
index 99494c17e5b98e30cb8d2f9da8b878f5d1696542..86f68218f6a446acbcf10c4db3229863249e2c9d 100644 (file)
@@ -79,6 +79,7 @@ int xlat_fmt_get_vp(fr_pair_t **out, request_t *request, char const *name)
                                &(tmpl_rules_t){
                                        .attr = {
                                                .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .prefix = TMPL_ATTR_REF_PREFIX_AUTO
                                        }
                                }) <= 0) return -4;
@@ -1152,6 +1153,7 @@ static xlat_action_t xlat_func_debug_attr(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcur
                                &(tmpl_rules_t){
                                        .attr = {
                                                .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .prefix = TMPL_ATTR_REF_PREFIX_AUTO
                                        }
                                }) <= 0) {
@@ -1200,6 +1202,7 @@ static xlat_action_t xlat_func_flatten(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor
                                &(tmpl_rules_t){
                                        .attr = {
                                                .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .prefix = TMPL_ATTR_REF_PREFIX_AUTO
                                        }
                                }) <= 0) {
@@ -1246,6 +1249,7 @@ static xlat_action_t xlat_func_unflatten(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcurs
                                &(tmpl_rules_t){
                                        .attr = {
                                                .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .prefix = TMPL_ATTR_REF_PREFIX_AUTO
                                        }
                                }) <= 0) {
@@ -1539,6 +1543,7 @@ static xlat_action_t xlat_func_map(TALLOC_CTX *ctx, fr_dcursor_t *out,
        tmpl_rules_t    attr_rules = {
                .attr = {
                        .dict_def = request->dict,
+                       .list_def = PAIR_LIST_REQUEST,
                        .prefix = TMPL_ATTR_REF_PREFIX_AUTO
                }
        };
@@ -1751,10 +1756,11 @@ static xlat_action_t xlat_func_eval(TALLOC_CTX *ctx, fr_dcursor_t *out,
                                    },
                                    &(tmpl_rules_t){
                                            .attr = {
+                                               .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .allow_unknown = false,
                                                .allow_unresolved = false,
                                                .allow_foreign = false,
-                                               .dict_def = request->dict
                                        },
                                        .at_runtime = true
                                    }) < 0) {
@@ -1827,10 +1833,11 @@ static xlat_action_t xlat_func_expr(TALLOC_CTX *ctx, fr_dcursor_t *out,
                                    },
                                    &(tmpl_rules_t){
                                        .attr = {
+                                               .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .allow_unknown = false,
                                                .allow_unresolved = false,
                                                .allow_foreign = false,
-                                               .dict_def = request->dict
                                        },
                                        .at_runtime = true
                                    }) < 0) {
@@ -2744,6 +2751,7 @@ static xlat_action_t xlat_func_pairs(TALLOC_CTX *ctx, fr_dcursor_t *out,
                                &(tmpl_rules_t){
                                        .attr = {
                                                .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .prefix = TMPL_ATTR_REF_PREFIX_AUTO
                                        }
                                }) <= 0) {
@@ -3901,6 +3909,7 @@ static xlat_action_t protocol_encode_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
                                &(tmpl_rules_t){
                                        .attr = {
                                                .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .prefix = TMPL_ATTR_REF_PREFIX_AUTO
                                        }
                                }) <= 0) {
index 0e260df1183cac0a64e2420c8142b5a1b4d5bd5f..ea98acde399ab10879cf0a55fd11d902e3e83798 100644 (file)
@@ -1459,7 +1459,8 @@ ssize_t _xlat_eval(TALLOC_CTX *ctx, char **out, size_t outlen, request_t *reques
                                      NULL,
                                      &(tmpl_rules_t){
                                        .attr = {
-                                               .dict_def = request->dict
+                                               .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                        }
                                      });
        if (len == 0) {
index 97869000c1ea69f4dbbc7ffa14435282ab7f26ff..f1a439c4a8417bfc351e37c671bde1a6e4c41355 100644 (file)
@@ -286,6 +286,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx)
                /* Strict rules for the update map as it's processed with limited functionality */
                .attr = {
                        .dict_def = dict_ldap_sync,
+                       .list_def = PAIR_LIST_REQUEST,
                        .allow_foreign = false,
                        .allow_unknown = false,
                        .allow_unresolved = false,
index e13e6f03f166b992cf5ded24d8c6e21e108d7a69..3d7d23bb153d1de0524b497e927f5d6931266cc1 100644 (file)
@@ -845,6 +845,7 @@ xlat_action_t cache_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
                                      &(tmpl_rules_t){
                                        .attr = {
                                                .dict_def = request->dict,
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .prefix = TMPL_ATTR_REF_PREFIX_AUTO
                                        }
                                      });
@@ -1013,6 +1014,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx)
        {
                tmpl_rules_t    parse_rules = {
                        .attr = {
+                               .list_def = PAIR_LIST_REQUEST,
                                .allow_foreign = true   /* Because we don't know where we'll be called */
                        }
                };
index 189e25c90059134f5a9ff3629108c642dcf8f6b1..1d6feac49e936aa6f31c6ce959af325b6791b8c2 100644 (file)
@@ -246,6 +246,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx)
                                 T_BACK_QUOTED_STRING, NULL,
                                 &(tmpl_rules_t) {
                                        .attr = {
+                                               .list_def = PAIR_LIST_REQUEST,
                                                .allow_foreign = true,
                                                .allow_unresolved = false,
                                                .allow_unknown = false
index 2f3863f6b1cc2774294e485ef672ff14fb9c97f8..7ddfaa7525086f50a4904eb05388bc5cec3c1ba3 100644 (file)
@@ -200,6 +200,7 @@ static xlat_action_t json_encode_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
                                              &json_arg_parse_rules,
                                              &(tmpl_rules_t){
                                                .attr = {
+                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .dict_def = request->dict
                                                }
                                              });
index 539340f1032e88e0c674bcad8e7d58957e857644..03fa4c6f108ca3257a4f31ce97d421c25006d549 100644 (file)
@@ -1999,6 +1999,7 @@ static int mod_instantiate(module_inst_ctx_t const *mctx)
        {
                tmpl_rules_t    parse_rules = {
                        .attr = {
+                               .list_def = PAIR_LIST_REQUEST,
                                .allow_foreign = true   /* Because we don't know where we'll be called */
                        }
                };
index 5f0c8bcfc99ec5daf93860b61be2491f3d3cd2a9..f33db0ff84f2d0b0e0b8af1a6bd78c384fdfcf7d 100644 (file)
@@ -528,6 +528,7 @@ static unlang_action_t CC_HINT(nonnull) mod_do_linelog(rlm_rcode_t *p_result, mo
                                         NULL,
                                         &(tmpl_rules_t){
                                                .attr = {
+                                                       .list_def = PAIR_LIST_REQUEST,
                                                        .dict_def = request->dict,
                                                        .allow_unknown = true,
                                                        .allow_unresolved = false,