]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_json: Catch wrong "reset" payload
authorPhil Sutter <phil@nwl.cc>
Wed, 13 Sep 2023 18:32:37 +0000 (20:32 +0200)
committerPhil Sutter <phil@nwl.cc>
Fri, 22 Sep 2023 08:55:25 +0000 (10:55 +0200)
The statement happily accepted any valid expression as payload and
assumed it to be a tcpopt expression (actually, a special case of
exthdr). Add a check to make sure this is the case.

Standard syntax does not provide this flexibility, so no need to have
the check there as well.

Fixes: 5d837d270d5a8 ("src: add tcp option reset support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/parser_json.c

index e8a175de8067638d222730d433f745eff437fe87..9532f7be04d67ee0412f0e78ea03818af5198120 100644 (file)
@@ -2797,7 +2797,14 @@ static struct stmt *json_parse_optstrip_stmt(struct json_ctx *ctx,
 {
        struct expr *expr = json_parse_expr(ctx, value);
 
-       return expr ? optstrip_stmt_alloc(int_loc, expr) : NULL;
+       if (!expr ||
+           expr->etype != EXPR_EXTHDR ||
+           expr->exthdr.op != NFT_EXTHDR_OP_TCPOPT) {
+               json_error(ctx, "Illegal TCP optstrip argument");
+               return NULL;
+       }
+
+       return optstrip_stmt_alloc(int_loc, expr);
 }
 
 static struct stmt *json_parse_stmt(struct json_ctx *ctx, json_t *root)