summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/scanner.l21
-rwxr-xr-xtests/shell/testcases/include/0016maxdepth_08
2 files changed, 17 insertions, 12 deletions
diff --git a/src/scanner.l b/src/scanner.l
index 80b5a5f0..d32adf48 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -672,17 +672,13 @@ static void scanner_pop_buffer(yyscan_t scanner)
state->indesc = state->indescs[--state->indesc_idx];
}
-static struct error_record *scanner_push_file(struct nft_ctx *nft, void *scanner,
- const char *filename, const struct location *loc)
+static void scanner_push_file(struct nft_ctx *nft, void *scanner,
+ const char *filename, const struct location *loc)
{
struct parser_state *state = yyget_extra(scanner);
struct input_descriptor *indesc;
YY_BUFFER_STATE b;
- if (state->indesc_idx == MAX_INCLUDE_DEPTH)
- return error(loc, "Include nested too deeply, max %u levels",
- MAX_INCLUDE_DEPTH);
-
b = yy_create_buffer(nft->f[state->indesc_idx], YY_BUF_SIZE, scanner);
yypush_buffer_state(b, scanner);
@@ -697,8 +693,6 @@ static struct error_record *scanner_push_file(struct nft_ctx *nft, void *scanner
state->indescs[state->indesc_idx] = indesc;
state->indesc = state->indescs[state->indesc_idx++];
list_add_tail(&indesc->list, &state->indesc_list);
-
- return NULL;
}
static int include_file(struct nft_ctx *nft, void *scanner,
@@ -708,6 +702,12 @@ static int include_file(struct nft_ctx *nft, void *scanner,
struct error_record *erec;
FILE *f;
+ if (state->indesc_idx == MAX_INCLUDE_DEPTH) {
+ erec = error(loc, "Include nested too deeply, max %u levels",
+ MAX_INCLUDE_DEPTH);
+ goto err;
+ }
+
f = fopen(filename, "r");
if (f == NULL) {
erec = error(loc, "Could not open file \"%s\": %s\n",
@@ -715,10 +715,7 @@ static int include_file(struct nft_ctx *nft, void *scanner,
goto err;
}
nft->f[state->indesc_idx] = f;
-
- erec = scanner_push_file(nft, scanner, filename, loc);
- if (erec != NULL)
- goto err;
+ scanner_push_file(nft, scanner, filename, loc);
return 0;
err:
erec_queue(erec, state->msgs);
diff --git a/tests/shell/testcases/include/0016maxdepth_0 b/tests/shell/testcases/include/0016maxdepth_0
new file mode 100755
index 00000000..89eb13c4
--- /dev/null
+++ b/tests/shell/testcases/include/0016maxdepth_0
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+set -e
+
+tmpfile=$(mktemp)
+
+echo 'include "/tmp/rules.nft"' > $tmpfile
+$NFT -f $tmpfile || exit 0