From f24d68ed6782d561c5a37553f373948dab104804 Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Tue, 26 Nov 2013 11:03:11 -0500 Subject: [PATCH] Ensure that "break" can only occur in "foreach" sections --- src/main/modcall.c | 19 +++++++++++++++++-- src/tests/keywords/break-error | 11 +++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/tests/keywords/break-error diff --git a/src/main/modcall.c b/src/main/modcall.c index 38a9abe15e..df0781f57c 100644 --- a/src/main/modcall.c +++ b/src/main/modcall.c @@ -1628,9 +1628,24 @@ static modcallable *do_compile_modforeach(modcallable *parent, return csingle; } -static modcallable *do_compile_modbreak(modcallable *parent, UNUSED rlm_components_t component) +static modcallable *do_compile_modbreak(modcallable *parent, + rlm_components_t component, CONF_ITEM const *ci) { modcallable *csingle; + CONF_SECTION const *cs = NULL; + + for (cs = cf_item_parent(ci); + cs != NULL; + cs = cf_item_parent(cf_sectiontoitem(cs))) { + if (strcmp(cf_section_name1(cs), "foreach") == 0) { + break; + } + } + + if (!cs) { + cf_log_err(ci, "'break' can only be used in a 'foreach' section"); + return NULL; + } csingle = do_compile_modgroup(parent, component, NULL, GROUPTYPE_SIMPLE, GROUPTYPE_SIMPLE); @@ -2059,7 +2074,7 @@ static modcallable *do_compile_modsingle(modcallable *parent, #ifdef WITH_UNLANG if (strcmp(modrefname, "break") == 0) { - return do_compile_modbreak(parent, component); + return do_compile_modbreak(parent, component, ci); } #endif diff --git a/src/tests/keywords/break-error b/src/tests/keywords/break-error new file mode 100644 index 0000000000..ca579aaa42 --- /dev/null +++ b/src/tests/keywords/break-error @@ -0,0 +1,11 @@ +update control { + Cleartext-Password := 'hello' +} + +update reply { + Filter-Id := "filter" +} + +if (User-Name == "bob") { + break # ERROR +} \ No newline at end of file -- 2.47.3