]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
scanner: better error reporting for CRLF line terminators
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 6 Jan 2025 23:00:50 +0000 (00:00 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 17 Jun 2025 09:21:37 +0000 (11:21 +0200)
commit 8c35615297983227cac1437edbe0cdedf4c2227b upstream.

Provide a hint to users that file is coming with CRLF line terminators,
maybe from a non-Linux OS.

Extend scanner.l to provide hint on CRLF in files:

 # file test.nft
 test.nft: ASCII text, with CRLF, LF line terminators
 # nft -f test.nft
 test.nft:1:13-14: Error: syntax error, unexpected CRLF line terminators
 table ip x {
             ^^

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/parser_bison.y
src/scanner.l

index 7c008f6801d94e66a9d2ad351c489e652922dca5..3258c7e632c0966ef74a2679a1bb36525bf6738d 100644 (file)
@@ -233,6 +233,7 @@ int nft_lex(void *, void *, void *);
 
 %token TOKEN_EOF 0             "end of file"
 %token JUNK                    "junk"
+%token CRLF                    "CRLF line terminators"
 
 %token NEWLINE                 "newline"
 %token COLON                   "colon"
index e88a2643f34f8bf51c4fc7a0b07b7ceda362e8c2..00816c939253a2ee35da93f412ed7ecf69170b2e 100644 (file)
@@ -114,6 +114,7 @@ extern void yyset_column(int, yyscan_t);
 
 space          [ ]
 tab            \t
+newline_crlf   \r\n
 newline                \n
 digit          [0-9]
 hexdigit       [0-9a-fA-F]
@@ -862,6 +863,8 @@ addrstring  ({macaddr}|{ip4addr}|{ip6addr})
                                return STRING;
                        }
 
+{newline_crlf}         {       return CRLF; }
+
 \\{newline}            {
                                reset_pos(yyget_extra(yyscanner), yylloc);
                        }