Skip to contentSkip to conversation

scanner: better error reporting for CRLF line terminators

PATCH New Pablo Neira Ayuso 1 participant 1 message Jan 6, 2025 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 scanner: better error reporting for CRLF line terminators

Provide a hint to users that file are coming with CRLF line terminators maybe from 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 {
             ^^
---
 src/parser_bison.y | 1 +
 src/scanner.l      | 3 +++
 2 files changed, 4 insertions(+)
src/parser_bison.y +1 -0
index e107ddfd3e4e..addeb03ac21c 100644
@@ -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"
src/scanner.l +3 -0
index 9ccbc22d2120..4787cc12f993 100644
@@ -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);
 			}
Signature · 1 line
2.30.2