summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2021-06-11 16:07:02 +0200
committerPhil Sutter <phil@nwl.cc>2021-06-14 13:31:07 +0200
commitf7b0eef8391ae7f89a3a82f6eeecaebe199224d7 (patch)
treeb56c519be1a5c93afc3eaf92f474b8d77e84558d /src
parent7c3b2a7acbdc793b822a230ec0c28086c7d0365d (diff)
parser_json: Fix for memleak in tcp option error path
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>
Diffstat (limited to 'src')
-rw-r--r--src/parser_json.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/parser_json.c b/src/parser_json.c
index e6a0233a..bb0e4169 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -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;