Re: [nft PATCH] src: Quote user-defined names

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Phil,

Another spin on this, let's try to make a final decision on this asap.

In this case, this patch passes the quoted string to the kernel, so
the listing shows it again.

Still, problem here is that the shell is stripping off the quotes
unless I escape them, ie.

        nft add chain "x" "y"

enters the unquoted path from the scannner. So I have to use:

        nft add chain \"x\" \"y\"

or:

        nft add chain x '"y"'

I think your patch fixes the problem with using keywords as object
names, which we could also fix via a rule that deals with this.

The problem with using any arbitrary name would be still there, unless
the user escapes the quotes.

On the other hand, if we quote the string in the listing by default,
we clearly show that these are user-defined, which is not a bad idea.
However, we don't get much from showing quotes by default on listings,
I mean, this is not solving the arbitrary name problem from the input
path, which I think it the real problem.

Then, enforcing quotes since the beginning would not have helped
either, because of the shell behaviour.

Exploring another patch here to allow to use keywords without quotes
as object names, it won't look nice in bison, since we will need
something similar to what we do in primary_rhs_expr for TCP, UDP...
but it will work.
diff --git a/src/parser_bison.y b/src/parser_bison.y
index b20be3a896b0..e5143c40c794 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -550,6 +550,9 @@ int nft_lex(void *, void *, void *);
 %type <string>			extended_prio_name
 %destructor { xfree($$); }	extended_prio_name
 
+%type <string>			generic_identifier
+%destructor { xfree($$); }	generic_identifier
+
 %type <string>			dev_spec quota_unit
 %destructor { xfree($$); }	dev_spec quota_unit
 
@@ -2041,7 +2044,7 @@ tableid_spec 		: 	family_spec 	HANDLE NUM
 			}
 			;
 
-chain_spec		:	table_spec	identifier
+chain_spec		:	table_spec	generic_identifier
 			{
 				$$		= $1;
 				$$.chain.name	= $2;
@@ -2057,7 +2060,19 @@ chainid_spec 		: 	table_spec 	HANDLE NUM
 			}
 			;
 
-chain_identifier	:	identifier
+generic_identifier	:	STRING	{ $$ = $1; }
+			|	QUOTED_STRING
+			{
+				size_t len;
+
+				len = strlen($1) + 3;
+				$$ = xmalloc(len);
+				snprintf($$, len, "\"%s\"", $1);
+				xfree($1);
+			}
+			;
+
+chain_identifier	:	generic_identifier
 			{
 				memset(&$$, 0, sizeof($$));
 				$$.chain.name		= $1;

[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux