netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net
Subject: [PATCH nft 5/5] scanner: don't bug on too large values
Date: Mon,  1 Dec 2014 12:45:54 +0100	[thread overview]
Message-ID: <1417434354-5782-6-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1417434354-5782-1-git-send-email-pablo@netfilter.org>

Add a new ERROR symbol to handle scanning of too large values.

 <cmdline>:1:36-99: Error: bad value '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
 add rule ip test-ip4 input ct mark 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
instead of:

 BUG: nft: scanner.l:470: nft_lex: Assertion `0' failed.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/parser_bison.y |   15 ++++++++++++++-
 src/scanner.l      |   12 ++++++++----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/parser_bison.y b/src/parser_bison.y
index ad2951a..6c7a036 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -209,7 +209,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %token <val> NUM		"number"
 %token <string> STRING		"string"
 %token <string> QUOTED_STRING
-%destructor { xfree($$); }	STRING QUOTED_STRING
+%token <string> ERROR		"error"
+%destructor { xfree($$); }	STRING QUOTED_STRING ERROR
 
 %token LL_HDR			"ll"
 %token NETWORK_HDR		"nh"
@@ -465,6 +466,8 @@ static void location_update(struct location *loc, struct location *rhs, int n)
 %destructor { expr_free($$); }	list_expr
 %type <expr>			concat_expr map_lhs_expr
 %destructor { expr_free($$); }	concat_expr map_lhs_expr
+%type <expr>			error_expr
+%destructor { expr_free($$); }	error_expr
 
 %type <expr>			map_expr
 %destructor { expr_free($$); }	map_expr
@@ -1668,6 +1671,16 @@ expr			:	concat_expr
 			|	set_expr
 			|       map_expr
 			|	multiton_expr
+			|	error_expr
+			;
+
+error_expr		:	ERROR
+			{
+				$$ = NULL;
+				erec_queue(error(&@1, "bad value '%s'", $1),
+					   state->msgs);
+				YYERROR;
+			}
 			;
 
 set_expr		:	'{'	set_list_expr		'}'
diff --git a/src/scanner.l b/src/scanner.l
index f0ed8d4..8f14b0e 100644
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -458,16 +458,20 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
 {decstring}		{
 				errno = 0;
 				yylval->val = strtoull(yytext, NULL, 0);
-				if (errno != 0)
-					BUG();
+				if (errno != 0) {
+					yylval->string = xstrdup(yytext);
+					return ERROR;
+				}
 				return NUM;
 			}
 
 {hexstring}		{
 				errno = 0;
 				yylval->val = strtoull(yytext, NULL, 0);
-				if (errno != 0)
-					BUG();
+				if (errno != 0) {
+					yylval->string = xstrdup(yytext);
+					return ERROR;
+				}
 				return NUM;
 			}
 
-- 
1.7.10.4


      parent reply	other threads:[~2014-12-01 11:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-01 11:45 [PATCH nft 1/5] netlink_delinearize: clone on netlink_get_register(), release previous on _set() Pablo Neira Ayuso
2014-12-01 11:45 ` [PATCH nft 2/5] meta: set base field on clones Pablo Neira Ayuso
2014-12-01 11:45 ` [PATCH nft 3/5] tests: regression: fix "Listing is broken" instead of output mismatch Pablo Neira Ayuso
2014-12-01 11:45 ` Pablo Neira Ayuso
2014-12-01 11:45 ` [PATCH nft 4/5] tests: regression: any/ct: remove wrong output Pablo Neira Ayuso
2014-12-01 11:45 ` Pablo Neira Ayuso [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1417434354-5782-6-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).