]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_json: Parse into symbol range expression if possible
authorPhil Sutter <phil@nwl.cc>
Tue, 29 Jul 2025 15:55:17 +0000 (17:55 +0200)
committerPhil Sutter <phil@nwl.cc>
Thu, 31 Jul 2025 11:27:04 +0000 (13:27 +0200)
Apply the bison parser changes in commit 347039f64509e ("src: add symbol
range expression to further compact intervals") to JSON parser as well.

Fixes: 347039f64509e ("src: add symbol range expression to further compact intervals")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/parser_json.c

index be0de69837d8b5d1ec686fc1d155f3581665debb..71e44f19c9f17a7d129b057a4a09aba4c56a5b0c 100644 (file)
@@ -1360,7 +1360,7 @@ static struct expr *json_parse_prefix_expr(struct json_ctx *ctx,
 static struct expr *json_parse_range_expr(struct json_ctx *ctx,
                                          const char *type, json_t *root)
 {
-       struct expr *expr_low, *expr_high;
+       struct expr *expr_low, *expr_high, *tmp;
        json_t *low, *high;
 
        if (json_unpack_err(ctx, root, "[o, o!]", &low, &high))
@@ -1377,6 +1377,16 @@ static struct expr *json_parse_range_expr(struct json_ctx *ctx,
                expr_free(expr_low);
                return NULL;
        }
+       if (is_symbol_value_expr(expr_low) && is_symbol_value_expr(expr_high)) {
+               tmp = symbol_range_expr_alloc(int_loc,
+                                             SYMBOL_VALUE,
+                                             expr_low->scope,
+                                             expr_low->identifier,
+                                             expr_high->identifier);
+               expr_free(expr_low);
+               expr_free(expr_high);
+               return tmp;
+       }
        return range_expr_alloc(int_loc, expr_low, expr_high);
 }