* [PATCH nft,v2] scanner: handle files with CRLF line terminators
@ 2022-12-08 1:41 Pablo Neira Ayuso
2022-12-08 21:23 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Pablo Neira Ayuso @ 2022-12-08 1:41 UTC (permalink / raw)
To: netfilter-devel
Extend scanner.l to deal with CRLF, otherwise -f fails to load:
# file test.nft
test.nft: ASCII text, with CRLF, LF line terminators
# nft -f test.nft
test.nft:1:13-13: Error: syntax error, unexpected junk
table ip x {
^
Update full comment line to take CRLF too.
Add test to cover this usecase.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: Update comment_line to accept CRLF.
src/scanner.l | 6 ++++--
tests/shell/testcases/nft-f/crlf_0 | 17 +++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
create mode 100755 tests/shell/testcases/nft-f/crlf_0
diff --git a/src/scanner.l b/src/scanner.l
index e72a427aab48..254a23fb4068 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -113,7 +113,9 @@ extern void yyset_column(int, yyscan_t);
space [ ]
tab \t
-newline \n
+newline_lf \n
+newline_crlf \r\n
+newline ({newline_lf}|{newline_crlf})
digit [0-9]
hexdigit [0-9a-fA-F]
decstring {digit}+
@@ -124,7 +126,7 @@ string ({letter}|[_.])({letter}|{digit}|[/\-_\.])*
quotedstring \"[^"]*\"
asteriskstring ({string}\*|{string}\\\*|\\\*|{string}\\\*{string})
comment #.*$
-comment_line ^[ \t]*#.*\n
+comment_line ^[ \t]*#.*(\r\n|\n)
slash \/
timestring ([0-9]+d)?([0-9]+h)?([0-9]+m)?([0-9]+s)?([0-9]+ms)?
diff --git a/tests/shell/testcases/nft-f/crlf_0 b/tests/shell/testcases/nft-f/crlf_0
new file mode 100755
index 000000000000..7ba785c8656a
--- /dev/null
+++ b/tests/shell/testcases/nft-f/crlf_0
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+set -e
+
+RULESET="table ip foo {\r\n\tchain ber {\r\n\t}\r\n}"
+
+tmpfile=$(mktemp)
+if [ ! -w $tmpfile ] ; then
+ echo "Failed to create tmp file" >&2
+ exit 0
+fi
+
+trap "rm -rf $tmpfile" EXIT # cleanup if aborted
+
+echo -e "$RULESET" > $tmpfile
+
+$NFT -f "$tmpfile"
--
2.30.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH nft,v2] scanner: handle files with CRLF line terminators
2022-12-08 1:41 [PATCH nft,v2] scanner: handle files with CRLF line terminators Pablo Neira Ayuso
@ 2022-12-08 21:23 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2022-12-08 21:23 UTC (permalink / raw)
To: netfilter-devel
On Thu, Dec 08, 2022 at 02:41:51AM +0100, Pablo Neira Ayuso wrote:
> Extend scanner.l to deal with CRLF, otherwise -f fails to load:
>
> # file test.nft
> test.nft: ASCII text, with CRLF, LF line terminators
> # nft -f test.nft
> test.nft:1:13-13: Error: syntax error, unexpected junk
> table ip x {
> ^
>
> Update full comment line to take CRLF too.
>
> Add test to cover this usecase.
I am considering to keep back this patch. At quick glance, other
existing userspace tooling in Linux do not support for CRLF files.
I might follow up with a different approach: provide a more meaningful
error message, instead of saying "unexpected junk", report to the
users that the file contains CRLF and that needs to be fixed.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-12-08 21:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-08 1:41 [PATCH nft,v2] scanner: handle files with CRLF line terminators Pablo Neira Ayuso
2022-12-08 21:23 ` Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).