diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2022-01-02 21:39:42 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2022-01-15 18:11:22 +0100 |
commit | 5c2b2b0a2ba7c1403c6af3e59dd3f51d04a64645 (patch) | |
tree | bd49b55be7618b302307e808fc7c23e2acb59760 /src/erec.c | |
parent | 8ad4056e9182a03cf160b045532f0569d6b79c22 (diff) |
src: error reporting with -f and read from stdin
Reading from stdin requires to store the ruleset in a buffer so error
reporting works accordingly, eg.
# cat ruleset.nft | nft -f -
/dev/stdin:3:13-13: Error: unknown identifier 'x'
ip saddr $x
^
The error reporting infrastructure performs a fseek() on the file
descriptor which does not work in this case since the data from the
descriptor has been already consumed.
This patch adds a new stdin input descriptor to perform this special
handling which consists on re-routing this request through the buffer
functions.
Fixes: 935f82e7dd49 ("Support 'nft -f -' to read from stdin")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/erec.c')
-rw-r--r-- | src/erec.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -101,10 +101,11 @@ void print_location(FILE *f, const struct input_descriptor *indesc, iloc = &tmp->location; } } - if (indesc->name != NULL) + if (indesc->type != INDESC_BUFFER && indesc->name) { fprintf(f, "%s:%u:%u-%u: ", indesc->name, loc->first_line, loc->first_column, loc->last_column); + } } const char *line_location(const struct input_descriptor *indesc, @@ -145,6 +146,11 @@ void erec_print(struct output_ctx *octx, const struct error_record *erec, line = indesc->data; *strchrnul(line, '\n') = '\0'; break; + case INDESC_STDIN: + line = indesc->data; + line += loc->line_offset; + *strchrnul(line, '\n') = '\0'; + break; case INDESC_FILE: line = line_location(indesc, loc, buf, sizeof(buf)); break; |