]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_bison: Fix 'exists' keyword on Big Endian
authorPhil Sutter <phil@nwl.cc>
Fri, 13 Sep 2019 15:20:04 +0000 (17:20 +0200)
committerPhil Sutter <phil@nwl.cc>
Fri, 13 Sep 2019 23:05:03 +0000 (01:05 +0200)
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>
Acked-by: Florian Westphal <fw@strlen.de>
src/parser_bison.y
src/parser_json.c

index 3fccea6734c0b18b182e6c14d258efc6a69e4386..cd249c82d93822210b76b60552f44ef35092707c 100644 (file)
@@ -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);
                        }
                        ;
 
index 398ae19275c3bca55ed5471174cf4cb92c901e74..5dd410af4b074d2d169d9528804bf212c4a82f0e 100644 (file)
@@ -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));