]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
parser_json: Fix for memleak in tcp option error path
authorPhil Sutter <phil@nwl.cc>
Fri, 11 Jun 2021 14:07:02 +0000 (16:07 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 14 Jun 2021 11:31:07 +0000 (13:31 +0200)
If 'kind' value is invalid, the function returned without freeing 'expr'
first. Fix this by performing the check before allocation.

Fixes: cb21869649208 ("json: tcp: add raw tcp option match support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/parser_json.c

index e6a0233ab6ce347acab7e895865a3a67a74392e9..bb0e4169b477d296f82dc2f2fc433b74d334a2d2 100644 (file)
@@ -603,12 +603,12 @@ static struct expr *json_parse_tcp_option_expr(struct json_ctx *ctx,
                        "base", &kind, "offset", &offset, "len", &len)) {
                uint32_t flag = 0;
 
-               expr = tcpopt_expr_alloc(int_loc, kind,
-                                        TCPOPT_COMMON_KIND);
-
                if (kind < 0 || kind > 255)
                        return NULL;
 
+               expr = tcpopt_expr_alloc(int_loc, kind,
+                                        TCPOPT_COMMON_KIND);
+
                if (offset == TCPOPT_COMMON_KIND && len == 8)
                        flag = NFT_EXTHDR_F_PRESENT;