]> 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>
Fri, 10 Jan 2025 10:21:02 +0000 (11:21 +0100)
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 31ccc5e23c31e30af68ec8d82ace7dcb985d76b0..c8714812532def63fd1354a41056915c72fe31a4 100644 (file)
@@ -251,6 +251,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 9ccbc22d212043876ab70273238e8424ba85c772..4787cc12f993a1c65b4aa5a0f8cc8fff0e5871ba 100644 (file)
@@ -121,6 +121,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]
@@ -894,6 +895,8 @@ addrstring  ({macaddr}|{ip4addr}|{ip6addr})
                                return STRING;
                        }
 
+{newline_crlf}         {       return CRLF; }
+
 \\{newline}            {
                                reset_pos(yyget_extra(yyscanner), yylloc);
                        }