netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [nft PATCH v2] parser_bison: Fix 'exists' keyword on Big Endian
@ 2019-09-13 18:44 Phil Sutter
  2019-09-13 20:53 ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Sutter @ 2019-09-13 18:44 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, Florian Westphal

Size value passed to constant_expr_alloc() must correspond with actual
data size, otherwise wrong portion of data will be taken later when
serializing into netlink message.

Booleans require really just a bit, but make type of boolean_keys be
uint8_t (introducing new 'val8' name for it) and pass the data length
using sizeof() to avoid any magic numbers.

While being at it, fix len value in parser_json.c as well although it
worked before due to the value being rounded up to the next multiple of
8.

Fixes: 9fd9baba43c8e ("Introduce boolean datatype and boolean expression")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Changes since v1:
- Dropped pointless 'sizeof(char)' factor from product in
  src/parser_json.c.
---
 src/parser_bison.y | 5 +++--
 src/parser_json.c  | 3 ++-
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/parser_bison.y b/src/parser_bison.y
index 3fccea6734c0b..cd249c82d9382 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -135,6 +135,7 @@ int nft_lex(void *, void *, void *);
 %union {
 	uint64_t		val;
 	uint32_t		val32;
+	uint8_t			val8;
 	const char *		string;
 
 	struct list_head	*list;
@@ -800,7 +801,7 @@ int nft_lex(void *, void *, void *);
 
 %type <expr>			boolean_expr
 %destructor { expr_free($$); }	boolean_expr
-%type <val>			boolean_keys
+%type <val8>			boolean_keys
 
 %type <expr>			exthdr_exists_expr
 %destructor { expr_free($$); }	exthdr_exists_expr
@@ -3964,7 +3965,7 @@ boolean_expr		:	boolean_keys
 			{
 				$$ = constant_expr_alloc(&@$, &boolean_type,
 							 BYTEORDER_HOST_ENDIAN,
-							 1, &$1);
+							 sizeof($1) * BITS_PER_BYTE, &$1);
 			}
 			;
 
diff --git a/src/parser_json.c b/src/parser_json.c
index 398ae19275c3b..5dd410af4b074 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -351,7 +351,8 @@ static struct expr *json_parse_immediate(struct json_ctx *ctx, json_t *root)
 	case JSON_FALSE:
 		buf[0] = json_is_true(root);
 		return constant_expr_alloc(int_loc, &boolean_type,
-					   BYTEORDER_HOST_ENDIAN, 1, buf);
+					   BYTEORDER_HOST_ENDIAN,
+					   BITS_PER_BYTE, buf);
 	default:
 		json_error(ctx, "Unexpected JSON type %s for immediate value.",
 			   json_typename(root));
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [nft PATCH v2] parser_bison: Fix 'exists' keyword on Big Endian
  2019-09-13 18:44 [nft PATCH v2] parser_bison: Fix 'exists' keyword on Big Endian Phil Sutter
@ 2019-09-13 20:53 ` Florian Westphal
  2019-09-13 20:56   ` Phil Sutter
  0 siblings, 1 reply; 4+ messages in thread
From: Florian Westphal @ 2019-09-13 20:53 UTC (permalink / raw)
  To: Phil Sutter; +Cc: Pablo Neira Ayuso, netfilter-devel, Florian Westphal

Phil Sutter <phil@nwl.cc> wrote:
> Size value passed to constant_expr_alloc() must correspond with actual
> data size, otherwise wrong portion of data will be taken later when
> serializing into netlink message.
> 
> Booleans require really just a bit, but make type of boolean_keys be
> uint8_t (introducing new 'val8' name for it) and pass the data length
> using sizeof() to avoid any magic numbers.
> 
> While being at it, fix len value in parser_json.c as well although it
> worked before due to the value being rounded up to the next multiple of
> 8.

Looks good, thanks Phil.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [nft PATCH v2] parser_bison: Fix 'exists' keyword on Big Endian
  2019-09-13 20:53 ` Florian Westphal
@ 2019-09-13 20:56   ` Phil Sutter
  2019-09-13 22:35     ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: Phil Sutter @ 2019-09-13 20:56 UTC (permalink / raw)
  To: Florian Westphal; +Cc: Pablo Neira Ayuso, netfilter-devel

Hi!

On Fri, Sep 13, 2019 at 10:53:44PM +0200, Florian Westphal wrote:
> Phil Sutter <phil@nwl.cc> wrote:
> > Size value passed to constant_expr_alloc() must correspond with actual
> > data size, otherwise wrong portion of data will be taken later when
> > serializing into netlink message.
> > 
> > Booleans require really just a bit, but make type of boolean_keys be
> > uint8_t (introducing new 'val8' name for it) and pass the data length
> > using sizeof() to avoid any magic numbers.
> > 
> > While being at it, fix len value in parser_json.c as well although it
> > worked before due to the value being rounded up to the next multiple of
> > 8.
> 
> Looks good, thanks Phil.

So that's an ACK? :)

Cheers, Phil

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [nft PATCH v2] parser_bison: Fix 'exists' keyword on Big Endian
  2019-09-13 20:56   ` Phil Sutter
@ 2019-09-13 22:35     ` Florian Westphal
  0 siblings, 0 replies; 4+ messages in thread
From: Florian Westphal @ 2019-09-13 22:35 UTC (permalink / raw)
  To: Phil Sutter, Florian Westphal, Pablo Neira Ayuso, netfilter-devel

Phil Sutter <phil@nwl.cc> wrote:
> On Fri, Sep 13, 2019 at 10:53:44PM +0200, Florian Westphal wrote:
> > Phil Sutter <phil@nwl.cc> wrote:
> > > Size value passed to constant_expr_alloc() must correspond with actual
> > > data size, otherwise wrong portion of data will be taken later when
> > > serializing into netlink message.
> > > 
> > > Booleans require really just a bit, but make type of boolean_keys be
> > > uint8_t (introducing new 'val8' name for it) and pass the data length
> > > using sizeof() to avoid any magic numbers.
> > > 
> > > While being at it, fix len value in parser_json.c as well although it
> > > worked before due to the value being rounded up to the next multiple of
> > > 8.
> > 
> > Looks good, thanks Phil.
> 
> So that's an ACK? :)

Yes, feel free to push this.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-13 22:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-13 18:44 [nft PATCH v2] parser_bison: Fix 'exists' keyword on Big Endian Phil Sutter
2019-09-13 20:53 ` Florian Westphal
2019-09-13 20:56   ` Phil Sutter
2019-09-13 22:35     ` Florian Westphal

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).