From: Alan T. DeKok Date: Tue, 19 Jan 2021 14:49:06 +0000 (-0500) Subject: do compile-time checks for unresolved attributes X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47314707c7664e6c8f6ccd9a64a01ca8998f7e99;p=thirdparty%2Ffreeradius-server.git do compile-time checks for unresolved attributes --- diff --git a/src/lib/unlang/xlat_tokenize.c b/src/lib/unlang/xlat_tokenize.c index 3b1d4e2b5db..7568155366d 100644 --- a/src/lib/unlang/xlat_tokenize.c +++ b/src/lib/unlang/xlat_tokenize.c @@ -635,6 +635,7 @@ static inline int xlat_tokenize_attribute(TALLOC_CTX *ctx, xlat_exp_t **head, xl node->flags.needs_resolving = tmpl_is_attr_unresolved(vpt); node->attr = vpt; + node->flags.needs_resolving = tmpl_is_attr_unresolved(vpt); } if (!fr_sbuff_next_if_char(in, '}')) { @@ -1653,6 +1654,7 @@ int xlat_resolve(xlat_exp_t **head, xlat_flags_t *flags, bool allow_unresolved) * FIXME - Produce proper error with marker */ if (!allow_unresolved) { + error_unresolved: fr_strerror_printf_push("Failed resolving attribute in expansion %%{%s}", node->fmt); return -1; @@ -1674,6 +1676,10 @@ int xlat_resolve(xlat_exp_t **head, xlat_flags_t *flags, bool allow_unresolved) } break; + case XLAT_ATTRIBUTE: + if (!allow_unresolved) goto error_unresolved; + break; + default: fr_assert(0); /* Should not have been marked as unresolved */ return -1; diff --git a/src/tests/keywords/xlat-unknown b/src/tests/keywords/xlat-unknown index 921b447101b..13ac85c1dbd 100644 --- a/src/tests/keywords/xlat-unknown +++ b/src/tests/keywords/xlat-unknown @@ -10,9 +10,10 @@ update reply { # reference here should be to an unknown attribute, # and the dereference should fail. # -if ("%{reply.WiMAX.Capability.Release}" == "foo") { +if ("%{reply.WiMAX.Capability.Release}" == "foo") { # ERROR test_fail } else { - success -} \ No newline at end of file + # if it isn't a parse error, then it's a run-time error, + test_fail +}