Skip to contentSkip to conversation

scanner: handle files with CRLF line terminators

PATCH Superseded Pablo Neira Ayuso 1 participant 1 message Dec 7, 2022 netfilter

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 scanner: handle files with CRLF line terminators

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 {
             ^

Add test to cover this usecase.

---
 src/scanner.l                      |  4 +++-
 tests/shell/testcases/nft-f/crlf_0 | 17 +++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100755 tests/shell/testcases/nft-f/crlf_0
src/scanner.l +3 -1
index e72a427aab48..358fba495759 100644
@@ -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}+
tests/shell/testcases/nft-f/crlf_0 new file +17 -0
new file mode 100755
index 000000000000..7ba785c8656a
@@ -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"
Signature · 1 line
2.30.2