From: Alan T. DeKok Date: Fri, 9 Aug 2019 20:53:22 +0000 (-0400) Subject: don't create child ctx for $INCLUDE X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=debfa0dd0d7200cbae5a94360efd2062a7ea7b60;p=thirdparty%2Ffreeradius-server.git don't create child ctx for $INCLUDE instead, use the current one. And then check it post-facto to see if it mucked up the stack depth. --- diff --git a/src/lib/util/dict.c b/src/lib/util/dict.c index 50063283dd8..bdefbc1de37 100644 --- a/src/lib/util/dict.c +++ b/src/lib/util/dict.c @@ -5176,7 +5176,7 @@ static int _dict_from_file(dict_from_file_ctx_t *ctx, */ if (strncasecmp(argv[0], "$INCLUDE", 8) == 0) { int rcode; - dict_from_file_ctx_t nctx = *ctx; + int stack_depth = ctx->stack_depth; /* * Allow "$INCLUDE" or "$INCLUDE-", but @@ -5195,7 +5195,7 @@ static int _dict_from_file(dict_from_file_ctx_t *ctx, * parent. */ - rcode = _dict_from_file(&nctx, dir, argv[1], fn, line); + rcode = _dict_from_file(ctx, dir, argv[1], fn, line); if ((rcode == -2) && (argv[0][8] == '-')) { fr_strerror_printf(NULL); /* delete all errors */ rcode = 0; @@ -5207,12 +5207,22 @@ static int _dict_from_file(dict_from_file_ctx_t *ctx, return -1; } - /* - * Fixups are added to the head of the - * list, so copy the new head over to the - * parent. - */ - ctx->enum_fixup = nctx.enum_fixup; + if (ctx->stack_depth < stack_depth) { + fr_strerror_printf_push("unexpected END-??? in $INCLUDE at %s[%d]", fn, line); + fclose(fp); + return -1; + } + + while (ctx->stack_depth > stack_depth) { + if (ctx->stack[ctx->stack_depth].nest == FR_TYPE_INVALID) { + ctx->stack_depth--; + continue; + } + + fr_strerror_printf_push("BEGIN-??? without END-... in file $INCLUDEd from %s[%d]", fn, line); + fclose(fp); + return -1; + } continue; } /* $INCLUDE */